SSH執行hql報錯:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
報錯信息:
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
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 = ?]