報錯信息:
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",這個問題就解決了。
希望對你有幫助。^_^