简体   繁体   English

Spring Boot 2.2.2 和“hibernate.hbm2ddl.auto=(create|create-drop|update|validate)”不起作用

[英]Spring Boot 2.2.2 and "hibernate.hbm2ddl.auto=(create|create-drop|update|validate)" not working

My application is based on Spring Boot 2.2.2.RELEASE and PostgreSQL.我的应用程序基于 Spring Boot 2.2.2.RELEASE 和 PostgreSQL。 I am relying on Spring's AutoConfiguration as far as persistence is concerned.就持久性而言,我依赖 Spring 的 AutoConfiguration。 My application.properties file contains the following:我的 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

For some reason the setting for spring.jpa.properties.hibernate.hbm2ddl.auto=create is ignored by Spring - independent of its value - whereas the spring.jpa.properties.javax... properties are applied correctly which is easy to verify by looking at the generated SQL file (createDb.sql and dropDb.sql).由于某种原因spring.jpa.properties.hibernate.hbm2ddl.auto=create的设置被 Spring 忽略 - 与其值无关 - 而spring.jpa.properties.javax...属性被正确应用,这很容易验证通过查看生成的 SQL 文件(createDb.sql 和 dropDb.sql)。

Does anybody have any idea what the reason for this behaviour could be?有没有人知道这种行为的原因可能是什么? I would really be thankful as I have been trying to find the root cause for this issue for more than a day now?我真的很感激,因为我已经尝试找到这个问题的根本原因超过一天了?

Just as a side node: Spring Boot 2.0.5.RELEASE behaves the same.就像一个侧节点:Spring Boot 2.0.5.RELEASE 的行为相同。

You can have a look here:你可以看看这里:

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

You need to set the property: spring.jpa.hibernate.ddl-auto=create您需要设置属性: spring.jpa.hibernate.ddl-auto=create

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 hibernate.hbm2ddl.auto 设置为创建时,如果 postgresql 需要,我如何让 hibernate 执行 CREATE DATABASE - How do I get hibernate to execute CREATE DATABASE if necessary for postgresql when hibernate.hbm2ddl.auto is set to create hibernate.hbm2ddl.auto与auto不会添加新列 - hibernate.hbm2ddl.auto with auto does not add new column 休眠:如何手动创建删除架构? - Hibernate:How to create-drop schema manually? 获取休眠异常:org.hibernate.exception.SQLGrammarException:访问表元数据时出错,HBM2DDL_AUTO 设置为更新 - getting hibernate exception: org.hibernate.exception.SQLGrammarException: Error accessing table metadata with HBM2DDL_AUTO set to update 如何配置Spring Boot,Spring JPA,Spring Test和Hibernate创建,使用和删除给定的PostgreSQL模式? - How can I configure Spring Boot, Spring JPA, Spring Test, and Hibernate to create, use, and drop a given PostgreSQL schema? PostgreSQL + Hibernate + Spring 自动创建数据库 - PostgreSQL + Hibernate + Spring auto create database Spring Boot自动创建PostgreSQL数据库 - Spring Boot auto create postgresql Database 当为 Postgres DB 的属性 spring.jpa.hibernate.ddl-auto 提供更新值时,Hibernate 不会生成序列 - Hibernate does not generate sequences when update value is provided to the property spring.jpa.hibernate.ddl-auto for Postgres DBs 如果我将数据源从 `H2` 切换到 `postgresql`,`hibernate.hbm2ddl.import_files` 属性将停止工作 - `hibernate.hbm2ddl.import_files` property stops working if I switch the datasource from `H2` to `postgresql` 通过 JDBC 语句执行 DDL 删除模式的 Spring Boot 错误 - Spring Boot Error executing DDL drop schema via JDBC Statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM