Criteria接口的Projections类主要用于帮助Criteria接口完成数据的分组查询和统计功能:
List cats=session.createCriteria(Cat.class)
.setProjection(Projections.projectionList()
.add(Projections.rowCount())
.add(Projections.avg("weight"))
.add(Projections.max("weight"))
.add(Projections.min("weight"))
.add(Projections.groupProperty("color"))
).addOrder(Order.asc("color")).list();
示例代码相当于:
select color,count(*),avg(weight),max(weight),min(weight),min(weight) from cat group by color order by color asc;
posted on 2007-05-15 08:50
josson 阅读(2933)
评论(0) 编辑 收藏 所属分类:
Hibernate