Reputation: 2961
is there a way to write hibernate criteria for the following sql:
select count(*) from tableA group by columnA, columnB, columnC;
Basically, I want to exclude the group property from the select clause which is added by default.
Example:
session.createCriteria(TableA.class)
.setProjection(Projections.projectionList()
.add(Projections.groupProperty("columnA"))
.add(Projections.groupProperty("columnB"))
.add(Projections.groupProperty("columnC"))
.add(Projections.rowCount()));
will result in
select columnA, columnB, columnC, count(*) from tableA group by columnA, columnB, columnC;
Thanks.
Upvotes: 1
Views: 493
Reputation: 715
refer below code::
Integer totalResult = ((Number)criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
You can also try this:::
int count = ((Long)getSession().createQuery("select count(*) from table_a group by column_a").uniqueResult()).intValue();
Upvotes: 1