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


    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();
  • 相关阅读:
    面向对象编程(一)
    函数嵌套(闭包)、阶乘、斐波那数列知识
    函数的定义及用法
    常见例子
    Python解析JSON详解
    linux yum install mvn
    消息组件
    websphere 安装中出现JNDI资源找不到问题总结
    多业务Nginx解决方式
    python-pip 安装使用问题
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5665638.html
Copyright © 2020-2023  润新知