• hibernate原生sql获取list<T>异常解决


    /**
    * <p>Title: getbigestMinIntegral</p>
    * <p>Description: 获取最大的MinIntegral(原则上即最高等级的MinIntegral)</p>
    * @param integral
    * @param storeNo
    * @return
    * @author hedongfei
    * @date 2019年3月14日
    */
    @Override
    public UserLevelEntity getbigestMinIntegral(String storeNo) {
          StringBuffer hql = new StringBuffer(" select * FROM user_level WHERE storeNo=:storeNo ORDER BY minIntegral desc LIMIT 0,1 ");

          Query q = this.getSession().createSQLQuery(hql.toString());
          q.setString("storeNo", storeNo);
          List<UserLevelEntity> result= q .list();
          if(result!=null && result.size()>0){
              return result.get(0);
           }
       return null;
    }

    以上写法报错,原因未知,猜测原因为:未正确转换对象。
    q .list()转换值为:
    [["40285b81697b444e01697b4abba70004","0000000065123b530165125c69b20006","2019-03-14 16:21:29","0000000065123b530165125c69b20006","2019-03-14 16:21:29","0","Lv.4",4,5000,10000,"5 ","","1001","1001"]]

     

    正确值应该为:

    [["40285b81697b444e01697b4abba70004","0000000065123b530165125c69b20006","2019-03-14 16:21:29","0000000065123b530165125c69b20006","2019-03-14 16:21:29","0","Lv.4",4,5000,10000,"5 ","","1001","1001"]]
    [{"agencyNo":"1001","createOper":"0000000065123b530165125c69b20006","createTime":"2019-03-14 16:19:56","delFlag":"0","description":"8 ","levelIcon":"","levelName":"Lv.1","mapCondition":{},"maxIntegral":499,"minIntegral":100,"position":2,"sheetRow":0,"sortFieldName":"createTime","sortType":"desc","storeNo":"1001","updateOpeTime":"2019-03-14 16:19:56","updateOper":"0000000065123b530165125c69b20006","uuid":"40285b81697b444e01697b4952890001"}]


    改变写法如下:改为添加转换实体类.addEntity();

    /**
    * <p>Title: getbigestMinIntegral</p>
    * <p>Description: 获取最大的MinIntegral(原则上即最高等级的MinIntegral)</p>
    * @param integral
    * @param storeNo
    * @return
    * @author hedongfei
    * @date 2019年3月14日
    */
    @Override
    public UserLevelEntity getbigestMinIntegral(String storeNo) {
          StringBuffer hql = new StringBuffer(" select * FROM user_level WHERE storeNo='"+storeNo+"' ORDER BY minIntegral desc LIMIT 0,1 ");

          List<UserLevelEntity> result= this.getSession().createSQLQuery(hql.toString()).addEntity(UserLevelEntity.class).list();
         if(result!=null && result.size()>0){
              return result.get(0);
          }
       return null;
    }



  • 相关阅读:
    May Lunchtime 2021 Division 1
    June Cook-Off 2021 Division 1
    Codeforces Round #733 (Div. 1 + Div. 2)
    腾讯云TDSQL MySQL版
    腾讯云TDSQL PostgreSQL版-产品优势
    腾讯云TDSQL PostgreSQL版 -应用场景
    腾讯云TDSQL PostgreSQL版 -最佳实践 |优化 SQL 语句
    腾讯云TDSQL PostgreSQL版 -最佳实践 |优化 SQL 语句
    腾讯云TDSQL监控库密码忘记问题解决实战
    腾讯云分布式数据库TDSQL在银行传统核心系统中的应用实践
  • 原文地址:https://www.cnblogs.com/hedongfei/p/10532773.html
Copyright © 2020-2023  润新知