Hibernate's Criteria API provides a powerful way to construct database queries. This article demonstrates how to use Criteria to implement a SQL query with GROUP BY and aggregate functions.
SQL Query
SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name <operator> value GROUP BY column_name
Criteria Implementation
Criteria criteria = session.createCriteria(SomeTable.class); criteria.add(Restrictions.lt("someColumn", value)); criteria.setProjection(Projections.projectionList() .add(Projections.groupProperty("someColumn")) .add(Projections.max("someColumn")) .add(Projections.min("someColumn")) .add(Projections.count("someColumn")));
Key Points
The above is the detailed content of How to Implement GROUP BY Clauses with Hibernate Criteria?. For more information, please follow other related articles on the PHP Chinese website!