因此,我正在尝试在jhipster应用程序中运行集成测试,该应用程序当前(默认情况下,未对测试配置进行任何更改)使用H2数据库。我已经运行了mvnw clean测试,但出现以下错误:
2018-08-09 16:05:56.340 INFO 276 --- [ main] .f.t.r.CustomAuditEventRepositoryIntTest : No active profile set, falling back to default profiles: default
2018-08-09 16:06:06.159 INFO 276 --- [ main] c.f.t.config.MetricsConfiguration : Initializing Metrics Log reporting
2018-08-09 16:06:16.258 ERROR 276 --- [ main] liquibase : classpath:config/liquibase/master.xml: config/liquibase/changelog/20180725185152_added_entity_Driver.xml::20180725185152-1::jhipster: Change Set config/liquibase/changelog/20180725185152_added_entity_Driver.xml::20180725185152-1::jhipster failed. **Error: Table "DRIVER" already exists**; SQL statement:
CREATE TABLE PUBLIC.driver (id BIGINT NOT NULL, first_name VARCHAR(255), middle_name VARCHAR(255), last_name VARCHAR(255), birth_date date, gender VARCHAR(255), suffix VARCHAR(255), weight FLOAT4, height VARCHAR(255), eye_color VARCHAR(255), hair_color VARCHAR(255), is_organ_donor BOOLEAN, drivers_license_id BIGINT, address_id BIGINT, CONSTRAINT PK_DRIVER PRIMARY KEY (id), UNIQUE (drivers_license_id)) [42101-197] [Failed SQL: CREATE TABLE PUBLIC.driver (id BIGINT NOT NULL, first_name VARCHAR(255), middle_name VARCHAR(255), last_name VARCHAR(255), birth_date date, gender VARCHAR(255), suffix VARCHAR(255), weight FLOAT4, height VARCHAR(255), eye_color VARCHAR(255), hair_color VARCHAR(255), is_organ_donor BOOLEAN, drivers_license_id BIGINT, address_id BIGINT, CONSTRAINT PK_DRIVER PRIMARY KEY (id), UNIQUE (drivers_license_id))]
所以错误“驱动程序表已经存在”让我思考
A:Liquibase在不需要时对数据库运行更改集,或者可能是对它们运行了两次?
或
B:在运行liquibase之前,实际上并没有清除H2数据库 变更集。
有什么想法吗?
更新:以下是测试目录的application.yml文件中与hibernate和liquibase相关的属性:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:TouchQuote2Backend;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
name:
username:
password:
jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
open-in-view: false
show-sql: false
hibernate:
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.hbm2ddl.auto: validate
liquibase:
contexts: test
我尝试更改休眠的ddl-auto属性以进行验证,但仍然会引发相同的错误。
答案 0 :(得分:3)
由于默认为create-drop
,最有可能让Hibernate生成了模式。按照Spring Boot docs, Appendix A:
spring.jpa.hibernate.ddl-auto =#DDL模式。这实际上是“ hibernate.hbm2ddl.auto”属性的快捷方式。使用嵌入式数据库且未检测到任何模式管理器时,默认值为“ create-drop”。否则,默认为“无”。
设置spring.jpa.hibernate.ddl-auto=validate
仅验证使用Liquibase创建的架构。