Spring boot jpa驼峰命名会被自动转成数据库下划线命名

时间:2020-08-21 23:37:45 类型:JAVA
字号:    

Spring boot jpa驼峰命名会被自动转成数据库下划线命名

例如:

@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


<