解決 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深一點…


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM