Can somebody please help me complete / clean up this query. I am trying to first get the number of rows in the table, then I need to actually fetch a set of rows. I am not sure how I can use the same criteria instance to perform both queries.
To fetch the count I have something like this:
Criteria criteria = session.createCriteria(MyTable.class);
criteria.setProjection(Projections.rowCount());
Integer count = (Integer) criteria.uniqueResult();
int numRows = count.intValue();
And to fetch the rows (I need only a subset for pagination purposes):
Criteria criteria = session.createCriteria(MyTable.class);
criteria.setFirstResult(offset);
criteria.setMaxResults(limit);
criteria.addOrder(Order.desc(orderBy.toString()));
List<MyType> myType = criteria.list();
Do I first need to Null out the projection or something like that so that I can use the criteria to fetch rows (after performing the count)?
I would love some help cleaning this up so that I can efficiently perform both queries and end up with the total number of rows and a list of results. Thanks!!