2016-04-14 22:27:55 1888 次浏览
http://stackoverflow.com/questions/8491796/hibernate-group-by-criteria-object Please refer to this for the example .The main point is to use the groupProperty() , and the related aggregate functions provided by the Projections class.
http://stackoverflow.com/questions/8491796/hibernate-group-by-criteria-object
Please refer to this for the example .The main point is to use the groupProperty()
, and the related aggregate functions provided by the Projections class.
For example :
SELECT column_name, max(column_name) , min (column_name) , count(column_name) FROM table_name WHERE column_name > xxxxx GROUP BY column_name
Its equivalent criteria object is :
List result = session.createCriteria(SomeTable.class) .add(Restrictions.ge("someColumn", xxxxx)) .setProjection( Projections.projectionList() .add(Projections.groupProperty("someColumn")) .add(Projections.max("someColumn")) .add(Projections.min("someColumn")) .add(Projections.count("someColumn") ) ).list();
评论