1. 程式人生 > >【Hibernate】could not instantiate class.. from tuple] with root cause

【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