postgresql - Spring Boot 2.2.2 和 "hibernate.hbm2ddl.auto=(create|create-drop|update|validate)"不工作

标签 postgresql hibernate spring-boot jpa hbm2ddl

我的应用程序基于 Spring Boot 2.2.2.RELEASE 和 PostgreSQL。就持久性而言,我依赖于 Spring 的自动配置。我的 application.properties 文件包含以下内容:

# Persistence
dbVendor=postgresql

# Basic connection options
spring.dataSource.driver-class-name=org.postgresql.Driver
spring.dataSource.url=jdbc:postgresql://is-0001/<database>
spring.dataSource.username=<username>
spring.dataSource.password=<password>

# Hibernate options
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.hbm2ddl.auto=create
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.implicit_naming_strategy=<package>.ImplicitNamingStrategyImpl
spring.jpa.properties.hibernate.physical_naming_strategy=<package>.PhysicalNamingStrategyImpl

# Options to create sql scripts
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=/development/projects/<project>/backend/sql/setup/createDb.sql
#spring.jpa.properties.javax.persistence.schema-generation.scripts.drop-target=/development/projects/<project>/backend/sql/setup/dropDb.sql

出于某种原因,Spring 忽略了 spring.jpa.properties.hibernate.hbm2ddl.auto=create 的设置 - 与其值无关 - 而 spring.jpa.properties。 javax... 属性已正确应用,这很容易通过查看生成的 SQL 文件(createDb.sql 和 dropDb.sql)进行验证。

有人知道这种行为的原因是什么吗?我真的很感激,因为我已经尝试找到这个问题的根本原因一天多了?

作为侧节点:Spring Boot 2.0.5.RELEASE 的行为相同。

最佳答案

你可以在这里看看:

https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-initialize-a-database-using-hibernate

需要设置属性:spring.jpa.hibernate.ddl-auto=create

关于postgresql - Spring Boot 2.2.2 和 "hibernate.hbm2ddl.auto=(create|create-drop|update|validate)"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59417335/

相关文章:

java - Hibernate 在单个事务中自动更新

spring - 通过 org.springframework.orm.hibernate4.LocalSessionFactoryBean 创建 HibernateTemplate

spring - 我们可以在同一个端口上运行多个 spring boot 应用程序吗?如果没有,为什么我们在 application.properties 中有上下文路径选项?

mysql - Spring 启动jpa : ddl-auto=create does not create schema

python - Ident 连接通过 psycopg2 失败,但通过命令行工作

sql - 如何将来自不同表的这两个查询合并为一个来计算百分比?

postgresql - Postgres (Amazon RDS) 如何计算加权平均值

unit-testing - 如何有效地使用 JUnit 和 Hibernate?

c# - 使用 EF 和 Dot Net Core 1(PostgreSQL 数据库)生成迁移时出错

java - Spring 启动 : How to add interceptors to static resources?