是否增加group by对Hibernate查询结果的影响

eg.

String hql = "select dr.date,sum(dr.click_num) as cn from DailyRecord dr  ";

hql += " where 1=1 ";

hql += " and dr.date > :date ";

...

hql += " group by dr.date ";//(1)

hql += " order by dr.date desc ";

   Session session = getSessionFactory().openSession();
        List<Object> result = null;
        try {
            org.hibernate.Query query = session.createQuery(hql.toString());
            SqlUtil.setQueryParameter(query, paramMap);
            result = query.list();
        } finally {
            session.flush();
            session.close();
        }

////////////////

此时,如果不加(1)处语句,进行查询,如果没有满足条件的记录,result不会为空,size = 1;但此时里面的Object每个域都会null

如果加了(1)处的分组语句,进行查询,如果没有满足条件的记录,result不会为空,但size = 0;

 

posted @ 2013-05-22 14:23  akingseu  阅读(229)  评论(0编辑  收藏  举报