edo*_*Dev 12 ddl jpa spring-data-jpa spring-boot
自从更新到 Spring Boot 2 后,我注意到在使用 spring.jpa.properties.javax.persistence.schema-generation.scripts.* 选项时生成 DDL 文件的方式发生了变化。
以前,在 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
Run Code Online (Sandbox Code Playgroud)
现在,升级到 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
Run Code Online (Sandbox Code Playgroud)
不确定这是框架的新行为还是我现在才出现的配置问题。这是我的 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
Run Code Online (Sandbox Code Playgroud)
我的配置有问题吗?如何设置以便在每次运行时重写 DDL 文件?
谢谢。
为了解决这个问题,您需要将此属性添加到您的配置中
spring.jpa.properties.hibernate.hbm2ddl.schema-generation.script.append=false
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅https://hibernate.atlassian.net/browse/HHH-11817。
| 归档时间: |
|
| 查看次数: |
738 次 |
| 最近记录: |