使用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