SSH執行hql報錯:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]

來源:互聯網
上載者:User

標籤:報錯資訊   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 = ?]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.