解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用

问题:

Springboot启动报错:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

Springboot 版本 1.4.3.RELEASE
Hibernate相关属性:
spring.jpa.hibernate.ddl-auto=validate

 

解决:

配置application.properties为

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

 

过程:

配置

debug=true
spring.jpa.show-sql=true

日志提示@Column(name)的注解与数据库字段不匹配。发现问题。

 

原因:

Springboot的JPA由Hibernate实现。Springboot中默认配置的物理命名策略naming.physical-strategy为org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy。把Identifier name用toUnderScoreCase下划线命名规则又转换一次…真是反直觉……

 

一般大公司都会对常用组件基于开源项目自己去做一套框架去使用,并不能完全发挥Springboot“无配置”整合第三方框架的优点,踩到的坑会比传统Spring深一点…

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值