数据库中的字段名是productName,实体中应当这样写
@Column(name = "productname")
private String productName;
如果按照数据库中字段ProductName,一样注解在实体类@Column(name = "productName")
执行sql语句时,会把驼峰字符转化为"_"+ 小写驼峰字符,查询时会变成product_name,所以会报异常:
error[org.hibernate.exception.SQLGrammarException: Unknown column 'fxenterpri0_.product_name' in 'field list']
sql执行语句:
Hibernate: select fxenterpri0_.id as id9_, fxenterpri0_.product_name as product_name from fx_enterprise fxenterpri0_ order by fxenterpri0_.id desc

本文介绍了一种常见问题,即数据库字段与实体类属性映射不一致导致的查询异常,并提供了解决方案。
6264

被折叠的 条评论
为什么被折叠?



