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

 

     

 

  上面这么信息,其实就是想表达如果想升级Hibernate到5.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的效果。

 

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

 

 

 

转载于:https://www.cnblogs.com/hehehaha/p/6147057.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值