试试这个:
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 列的对象(请记住,Hibernate 正在处理对象)。