java.sql.SQLException: Unknown column 'user0_.user_name' in 'field list' 报错问题

报错信息:

java.sql.SQLException: Unknown column 'user0_.user_name' in 'field list'
Query is: select user0_.id as id1_0_, user0_.user_name as user_nam2_0_, user0_.password as password3_0_ from user user0_
java thread: http-nio-8881-exec-1

Hibernate报错:说表里没有user表中没有 user_name 这一列,所以查询语句无法执行。

我报错的原因:

在 name 上 我指定 它 对应的是 数据库中的 userName 字段。

但是,hibernate 会 按照驼峰命名规范 将 userName 转成 user_name , 相当于 数据库中 userName == 实体类中的 user_name ( hibernate 自动帮我们转换 )

所有,只要 我把@Column( name="userName" ) 里的name 改成 name="username",这个问题就解决了。

 

希望对你有帮助。^_^

posted @ 2018-12-31 15:40  追梦滴小蜗牛  阅读(5578)  评论(1编辑  收藏  举报