public class MyBean { private long count; public MyBean(long count) { this.count = count; } public long getCount() { return count; }
public void setCount(long count) { this.count = count; } }Session session = ...; List<MyBean> resultList = (List<MyBean>) session.createQuery("SELECT new MyBean(count(e)) FROM Entity e GROUP BY e.property").list();
那么返回的就肯定是一个object数组
唯一的办法就是返回一个数组后 然后根据数据相对应
转换成实体bean 如果你要查询的时候直接返回bean 好像不可以
this.count = count;
} public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
}Session session = ...;
List<MyBean> resultList = (List<MyBean>) session.createQuery("SELECT new MyBean(count(e)) FROM Entity e GROUP BY e.property").list();