Can someone please help me fill out / clear this request. I try to get the number of rows in a table first, then I need to actually get a rowset. I am not sure how I can use the same instance of the criteria to fulfill both queries.
To get the counter, 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 extract the rows (I only need a subset for entire pages):
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 need to Zero the projection first or something like that so that I can use the criteria to extract the rows (after doing the count)?
I would really like to help clear this so that I can efficiently execute both queries and eventually get the total number of rows and a list of results. Thanks!!
source share