Possible Duplicate:
How do we count rows using Hibernate?
How do we count rows using Hibernate with where clause?
select count(*) from table where recName = 'any'
Possible Duplicate:
How do we count rows using Hibernate?
How do we count rows using Hibernate with where clause?
select count(*) from table where recName = 'any'
This questions was basically already answered on stackoverflow:
How do we count rows using Hibernate?
In addition to the solution using Projections you just have to add your where clause as an additional Criterion to the Criteria.
Criteria criteria = session.createCriteria("Book");
criteria.add(Restrictions.eq("title", "My Title"));
criteria.setProjection(Projections.rowCount());
Number numRows = (Number)criteria.uniqueResult();