hibernate使用dto接收纯sql结果集

1.返回结果集有name=值的方式
StringBuilder hql=new StringBuilder("SELECT  t1.ID as companyid ,t1.DEPARTNAME as departname,t1.MOBILE as  mobile ,t1.ADDRESS as address ,t4.QUARTER_SCORE as quarterscore , t4.ID as quarterscoreId , t5.auditnm  " +
        "from sys_depart t1 " +
        "LEFT JOIN ( " +
        "SELECT * FROM t_assist t2 " +
        "left JOIN ( " +
        "SELECT MAX(CREATE_DATE ) AS createdate FROM t_assist" +
        ")  t3 ON  t2.CREATE_DATE=t3.createdate) t4 " +
        "ON t1.ID = t4.ASSIST_UNIT  LEFT JOIN ( SELECT  ASSIST_UNIT,count(ASSIST_UNIT) AS auditnm " +
        "FROM " +
        "t_commodity" +
        "WHERE   ASSIST_UNIT is not null and STATUS <8  " +
        "GROUP BY ASSIST_UNIT " +
        " ) AS t5 ON t5.ASSIST_UNIT = t1.ID  where t1.STATUS= '1' " );
    hql.append("  and t4.QUARTER_SCORE >=85 ");

SQLQuery query = getSession().createSQLQuery(hql.toString()).addScalar("companyid", StandardBasicTypes.STRING).addScalar("departname",StandardBasicTypes.STRING) .addScalar("mobile",StandardBasicTypes.STRING).addScalar("address",StandardBasicTypes.STRING).addScalar("quarterscoreId",StandardBasicTypes.STRING).addScalar("quarterscore",StandardBasicTypes.BIG_DECIMAL)
         .addScalar("auditnm",StandardBasicTypes.INTEGER);
 List list = query.setResultTransformer(Transformers.aliasToBean(DepartDto.class)).list();

你可能感兴趣的:(hibernate使用dto接收纯sql结果集)