美文网首页
Spring boot JPA column with inco

Spring boot JPA column with inco

作者: sunny4handsome | 来源:发表于2017-12-10 16:04 被阅读0次

spring boot 配置JPA的实体类出现如下错误时:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column
错误描述:spring boot 会把数据中驼峰命名的字段改成下划线加小写的方式无查数据库。
比如数据库中字段米为userName,那么jpa生产的sql语句就会变成user_name,这样自然是查询不成功的。

解决办法有两个:
1、@Column(name = "username")用小写
2、在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

相关文章

网友评论

      本文标题:Spring boot JPA column with inco

      本文链接:https://www.haomeiwen.com/subject/xdrvixtx.html