問題:
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深一點…