HQL语句在有sum(),group by函数的时候如何返回一个javabean 而不是object数组,

解决方案 »

  1.   

    不知道楼主要干什么 既然有了sum()
    那么返回的就肯定是一个object数组
    唯一的办法就是返回一个数组后 然后根据数据相对应
    转换成实体bean 如果你要查询的时候直接返回bean 好像不可以
      

  2.   

    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();