hibernate groupby

时间:2012-04-14 07:17:10

标签: java hibernate

我想知道如何在休眠状态下制作群组。 我的代码在下面,但它不起作用请告诉我这是怎么做的:

Session session = getSession();
Criteria c = session.createCriteria(CardLog.class);
c.add(Restrictions.ge(CARD_PUNCHING_TIME, todaysDate));
c.setProjection(Projections.groupProperty(USER_ID));
c.addOrder(Order.desc(USER_ID));
cardLogList = c.list();                
System.out.println("----------------" + cardLogList);

1 个答案:

答案 0 :(得分:0)

我认为你必须像这样使用

Session session = getSession();
Criteria c = session.createCriteria(CardLog.class);
c.add(Restrictions.ge("bean property todaydate", todaysDate));
c.setProjection(Projections.groupProperty("bean property userId"));
c.addOrder(Order.desc("bean property userId"));
cardLogList = c.list();                
System.out.println("----------------" + cardLogList);