hibernate如何使用criteria查詢 oracle分组group by案例

hql语句:    (TicketDAOImpl)
public List listNumTicket(String status) throws Exception {
Session session=super.getSession();
ProjectionList projectionList = Projections.projectionList(); 
projectionList.add(Projections.groupProperty("project.resourceId"));  //需要分组的字段
projectionList.add(Projections.rowCount());   //每组的记录条数
Criteria criteria =null;
if(status!="") //当有条件时
{
Ticket ticket = new Ticket(); 
ticket.setStatus(status);
criteria = session.createCriteria(Ticket.class); 
criteria.add(Example.create(ticket)); 
}else
{
criteria = session.createCriteria(Ticket.class); 
}
criteria.setProjection(projectionList); 
List list = criteria.list(); 
 
return list;
}

action调用:
List yticketList=ticketService.listNumTicket("已修复"); //取值如下
Iterator iterator2 = yticketList.iterator();
while(iterator2.hasNext()){   
Object[] object=(Object[])iterator2.next();
Object id=object[0];
Object num=object[1];
if(id!=null){
Project project=projectService.findById(id.toString());
project.setyTicketNum(num.toString());
projectService.update(project);
}
}

你可能感兴趣的:(hibernate如何使用criteria查詢 oracle分组group by案例)