標籤:報錯資訊 sql query hql 問題 list tab ... mysq
報錯資訊:
ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped [from user where username = ?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
org.springframework.orm.hibernate3.HibernateQueryException: user is not mapped [from user where username = ?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
......
Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
......
看到資訊的第一反應,映射出錯
1.有無User.hbm.xml檔案
2.該設定檔是否載入到hibernate實體列表中
3.對應檔欄位是否與資料庫欄位一致,有無誤用關鍵字
--> 依舊錯誤(既然不是User的錯,那就是資料庫問題)
為圖方便一開始資料庫方言是MySQLDialect,相容性可能出現問題,改為Mysql5Dialet ,即配置<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
-->依舊錯誤(**資料庫語句錯誤?**)
String hql = "from user where username = ?";
List<User> list = this.getHibernateTemplate().find(hql, username); 錯誤???
重點:hql採用實體查詢技術,比如下面的例子:String hql=”from User user ”; List list=session.CreateQuery(hql).list(); 上面的代碼執行結果是,查詢出User實體物件所對應的所有資料,而且將資料封裝成User實體物件,並且放入List中返回
所以,上面的hql語句錯誤,hql語句,一定是物件查詢,特別是【tableName】 不要寫你要查詢的表,而是查詢的對象
(此處,user是資料庫表名,應該查詢的是User對象)
SSH執行hql報錯:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]