Spring boot jpa駝峰命名會被自動轉成數(shù)據(jù)庫下劃線命名
例如:
@Query(value=" select * from sorts where parentId = ?1 order by orders asc ",nativeQuery=true ) public ArrayList<Sorts> selectByParentId(Integer id) ;
在查詢時會變成 where parent_id
從而造成 column parent_id不存在
解決方案:
在application.properties中添加
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl