简体   繁体   English

Spring-Hibernate JPA Configuration中的问题设置方言

[英]Spring - Issue setting dialect in Hibernate JPA Configuration

I'm moving from a Spring Boot 1.5.9 to a normal Spring project. 我正在从Spring Boot 1.5.9迁移到普通的Spring项目。

In application.properties I've added application.properties我添加了

spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration
spring.autoconfigure.exclude[1]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.autoconfigure.exclude[2]=org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration
spring.autoconfigure.exclude[3]=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

In application.properties I have a line that defines the dialect I'm using, it worked properly with the autoconfiguration application.properties我有一行定义了我正在使用的方言,它与自动配置一起正常工作

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl

When I try to run the project with the new configuration class I have org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' , I have the same error with the autoconfiguration if i remove the dialect line. 当我尝试使用新的配置类运行项目时,我遇到了org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'出错,如果我删除了方言行,则会在自动配置中遇到相同的错误。 My way to specify the properties, including the dialect, in the configuration class is the following 在配置类中指定属性(包括方言)的方式如下

private Map<String, String> properties = new HashMap<String, String>();

public HibernateJpaConfig() {
    properties.put("hibernate.hbm2ddl.auto", "create-drop");
    properties.put("hibernate.ejb.naming_strategy", "org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl");
}

I noticed a warning message that might be my issue 我注意到可能是我的问题的警告消息

WARN 13292 --- [  restartedMain] org.hibernate.orm.deprecation            : HHH90000006: Attempted to specify unsupported NamingStrategy via setting [hibernate.ejb.naming_strategy]; NamingStrategy has been removed in favor of the split ImplicitNamingStrategy and PhysicalNamingStrategy; use [hibernate.implicit_naming_strategy] or [hibernate.physical_naming_strategy], respectively, instead.

If I try to replace the second value of the map with one of those I still have the same error. 如果我尝试用其中之一替换地图的第二个值,我仍然会遇到相同的错误。

Please look at this release note of spring boot. 请查看此弹簧靴发行说明。 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#naming-strategy https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#naming-strategy

I think problem is in naming_strategy. 我认为问题出在naming_strategy。

SpringNamingStrategy is no longer used as Hibernate 5.1 has removed support for the old NamingStrategy interface. 由于Hibernate 5.1删除了对旧NamingStrategy接口的支持,因此不再使用SpringNamingStrategy。 A new SpringPhysicalNamingStrategy is now auto-configured which is used in combination with Hibernate's default ImplicitNamingStrategy. 现在自动配置了一个新的SpringPhysicalNamingStrategy,它与Hibernate的默认ImplicitNamingStrategy结合使用。 This should be very close to (if not identical) to Spring Boot 1.3 defaults, however, you should check your Database schema is correct when upgrading. 这应该与Spring Boot 1.3的默认值非常接近(如果不相同),但是,升级时应该检查数据库模式是否正确。

If you were already using Hibernate 5 before upgrading, you may be using Hibernate's 5 default. 如果升级之前已经在使用Hibernate 5,则可能正在使用Hibernate 5的默认设置。 If you want to restore them after the upgrade, set this property in your configuration: 如果要在升级后还原它们,请在配置中设置此属性:

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.hibernate.naming.physical策略= org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM