码迷,mamicode.com
首页 > 数据库 > 详细

Hibernate HQL和原生SQL查询的一点区别

时间:2016-07-13 09:17:28      阅读:454      评论:0      收藏:0      [点我收藏+]

标签:

1.createSQLQuery

  1.1默认查询的结果为BigDecimal

  1.2通过addScalar("CGD_ID", StandardBasicTypes.LONG)可以将结果直接转为Long

     StringBuffer sb = new StringBuffer();
        sb.append("select g.CGD_ID from em_circle_apply_info a join em_circle_group_def g on a.CAI_CGD_ID = g.CGD_ID ");
        if (size != null) {
            sb.append(" where rownum < " + (size+1));
        }
        sb.append(" group by a.CAI_CGD_ID order by count(a.CAI_CGD_ID) desc ");
        Query query = this.getSession().createSQLQuery(sb.toString()).addScalar("CGD_ID", StandardBasicTypes.LONG);

2.createQuery

  2.1默认查询结果为Long

     StringBuffer sb = new StringBuffer();
     sb.append("select t.caiCgdId.cgdId from EmCircleApplyInfo t "); if (size != null) { sb.append(" where rownum < " + (size+1)); } sb.append(" group by t.caiCgdId.cgdId order by count(t.caiCgdId) desc"); Query query = this.getSession().createQuery(sb.toString()).setCacheable(true); List<BigDecimal> idList = query.list(); List<Long> ids = new ArrayList<Long>(); List<Long> ids = query.list();

 

Hibernate HQL和原生SQL查询的一点区别

标签:

原文地址:http://www.cnblogs.com/luoxiaolei/p/5665638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!