内容被附加到通过JPA脚本生成生成的DDL文件中,而不是被替换

时间:2018-10-11 08:28:06

标签: spring-boot jpa spring-data-jpa ddl

自从更新到Spring Boot 2之后,我注意到使用以下命令时DDL文件生成方式的行为有所变化: spring.jpa.properties.javax.persistence.schema-generation.scripts。*选项。

以前,在Spring Boot 1.5中,每当我运行我的应用程序或测试时(我也有用于检查这些文件内容的集成测试),DDL文件都会重新生成,例如:

drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists

现在,在升级到Spring Boot 2.0.5之后,每次我运行测试或应用程序时,内容都会以这种方式附加到DDL文件中:

drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists
drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists
drop table testSchema.App if exists
drop table testSchema.AppMetadata if exists
drop table testSchema.Server if exists
drop table testSchema.User if exists
drop table testSchema.UserRole if exists
drop table testSchema.UserToken if exists

不确定这是框架的新行为还是我现在遇到的配置问题。这是我的test.properties文件(正如已经说过的,正常运行应用程序时会发生相同的问题,但是配置相对相似)。

# ========= DATA SOURCE : DB connection ========
spring.datasource.url=jdbc:h2:mem:myDb;INIT=CREATE SCHEMA IF NOT EXISTS testSchema
spring.datasource.username=________
spring.datasource.password=________
# ========= JPA / HIBERNATE =========
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.default_schema=testSchema
# DDL operations via Hibernate =========
spring.jpa.hibernate.ddl-auto = none
spring.jpa.generate-ddl = false
spring.jpa.show-sql=false
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
# DDL operations via JPA =========
spring.jpa.properties.javax.persistence.schema-generation.database.action=drop-and-create
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=drop-and-create
spring.jpa.properties.javax.persistence.schema-generation.drop-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.scripts.drop-target=./src/test/resources/test_data/dbCreationTestFiles/jpaGenerated_drop_test_sys_db.ddl
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=./src/test/resources/test_data/dbCreationTestFiles/jpaGenerated_create_test_sys_db.ddl

我的配置有问题吗?我该如何设置以便每次运行都可以重写DDL文件?

谢谢。

0 个答案:

没有答案
相关问题