嘗試這種情況:
Criteria criteriaPurchaseRequest=this.session.createCriteria(PurchaseRequest.class);
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.groupProperty("current_state"));
projectionList.add(Projections.rowCount());
criteriaPurchaseRequest.setProjection(projectionList);
List results = criteriaPurchaseRequest.list();
要獲得的結果:
List results = criteriaPurchaseRequest.list();
Map currentStateMap = new HashMap();
Iterator it=results.iterator();
while (it.hasNext()){
Object obj[]=(Object[])it.next();
CurrentState currentState = (CurrentState)obj[0];
currentStateMap .put(currentState.getDescription().toLowerCase(), (Integer)obj[1]);
}
其中CurrentState是表示列current_state(記住,休眠正在與對象)的對象。
你的意思是'選擇current_state,count(*)來自PurchaseRequest Group By current_state'? – AlexS
@AlexS是的,這正是我的意思。 –