hibernate 返回自定義對象


關鍵代碼老是忘記 setResultTransformer(Transformers.aliasToBean(LabourResult.class)) 

代碼用例:

 1     public List<LabourResult> getLabourResult(String startTime, String endTime, Long uid) {
 2         String sql = "select b.name userNo, c.`no` taskDetailNo, sum(a.num) qty, sum(a.ngNum) ngQty\n" +
 3                 "from process_his a inner join `user` b on a.creUid=b.id\n" +
 4                 "     inner join t_produce_task_detail c on a.taskDetailId=c.id\n" +
 5                 "where 1=1 and a.creTime>='" + startTime + "' and a.creTime<='" + endTime + "' ";
 6         if (uid != null) {
 7             sql += " and a.creUid=" + uid;
 8         }
 9         sql += " group by a.creUid, a.taskDetailId\n" +
10                 "order by a.creUid, a.taskDetailId";
11         List labours = processHisDao.getSession().createSQLQuery(sql)
12                 .addScalar("userNo", StandardBasicTypes.STRING)
13                 .addScalar("taskDetailNo", StandardBasicTypes.STRING)
14                 .addScalar("qty", StandardBasicTypes.LONG)
15                 .addScalar("ngQty", StandardBasicTypes.LONG)
16                 .setResultTransformer(Transformers.aliasToBean(LabourResult.class)).list();
17         return labours;
18     }

 


免責聲明!

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



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