hql聚合函数返回实体

StringBuilder hql = new StringBuilder();
Map<String, Object> paras = new HashMap<String, Object>();
hql.append("select new tableBean(max(id) as id, sum(b) as b,sum(a) as a) from tableBean where 1=1");
hql.append(" group by orderNo order by id desc");
getSession().createQuery(hql.toString()).setProperties(paras).list();

 关键代码如上,在hql中直接创建对象:new tableBean(max(id) as id, sum(b) as b,sum(a) as a)

注tableBean实体需要有对应的构造方法;

且不可重新设置返回类型:query.setResultTransformer(Transformers.aliasToBean(tableBean.class)))

你可能感兴趣的:(hql聚合函数返回实体)