80. Hibernate 5.0命名策略使用naming-strategy 不起作用【从零开始学Spring Boot】

【原创文章,转载请注明出处】

       事情的起因:一不小心从1.3.3升级到了1.4.0版本,结果就碰到了各种悲催的事情了,好吧,Hibernate5.0的新特性就是其中一个坑,我们会发现我们配置的naming-strategy不生效了。那怎么办呢?请差此文,此文应该是可以解决您的困惑的。

 

       我们先看看Hibernate原文怎么说的:

       Hibernate 5

       Hibernate 5.1 is now used as the default JPA persistence provider. If you are upgrading from Spring Boot 1.3 you will be moving from Hibernate 4.3 to Hibernate 5.1. Please refer to Hibernate migration documentation for general upgrade instructions. In addition you should be aware of the following:

SpringNamingStrategy is no longer used as Hibernate 5.1 has removed support for the oldNamingStrategy interface. A new SpringPhysicalNamingStrategy is now auto-configured which is used in combination with Hibernate’s default 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.

If you were already using Hibernate 5 before upgrading, you may be using Hibernate’s 5 default. 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.PhysicalNamingStra

 

     

 

  上面这么信息,其实就是想表达如果想升级Hibernate5.1的话,那么之前的

hibernate.ejb.naming_strategy将不再被支持,而是被替换成了两个属性:

hibernate.physical_naming_strategy

hibernate.implicit_naming_strategy

 

这两个属性都是干嘛的呢?

 

       对于 implicit_naming_strategy Hibernate官方有这么一句话:

used whenever a table or column is not explicitly named to determine the name to use

       implicit naming strategy:隐式命名策略,使用此属性当我们使用的表或列没有明确指定一个使用的名称 。

    

   对于 physical_naming_strategy Hibernate官方有这么一句话:

used to convert a "logical name" (either implicit or explicit) name of a table or column into a physical name (e.g. following corporate naming guidelines)

       physical naming strategy:物理命名策略,用于转换“逻辑名称”(隐式或显式)的表或列成一个物理名称。

      

 

  1.     之后的才是重点哦,对于physical_naming_strategy有两个常用的配置:

org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

       对于PhysicalNamingStrategyStandardImplDefaultNamingStrategy的效果;对于SpringPhysicalNamingStrategy  

ImprovedNamingStrategy的效果。

 

       另外一个属性,好吧,其实我也不是很明白具体是怎么使用,以及这两个属性怎么配合使用,什么场景下出现什么特殊的效果。有知道的不吝赐教,在此谢过。

 

 

 

posted on 2016-08-05 10:03  疯子123  阅读(2035)  评论(0编辑  收藏  举报

导航