【Hibernate】could not instantiate class.. from tuple] with root cause


使用hibernate的過程中出現了這個問題,查詢語句如下:

1 String hql = "select new GoodsBean(id, name, price, proPic, sales, updatetime, marketReferencePrice) from GoodsBean where bigTypeId = ? order by views desc";
2 
3 Query query = this.getCurrentSession().createQuery(hql);
4 query.setInteger(0, Integer.valueOf(bid));
5 query.setFirstResult((p - 1) * pageSize);
6 query.setMaxResults(pageSize);
7 List<GoodsBean> goodsBeanList = (List<GoodsBean>)query.list();

運行到第七行時出現題目中的錯誤提示,最后在網上查詢資料,說是可能是入參為null,我看了下數據庫構造函數中的各參數,果真有一個參數的值為空,賦值后,正常了。

1 new GoodsBean(id, name, price, proPic, sales, updatetime, marketReferencePrice)

參考:https://blog.csdn.net/sunzhemin/article/details/9214435?locationnum=9


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM