Wednesday, 28 August 2013

Hibernate criteria return page and rowcount

Hibernate criteria return page and rowcount

Using Hibernate Criteria i am trying to achieve pagination but the problem
is that for every page fetch i have to make two db calls one for results
and another for total records count. Is there any efficient way so that in
a single db call i can get both the data or i can reduce db calls.
Criteria criteria=session.createCriteria(Student.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.add(Restrictions.ne("enquiryStatus", ENQUIRY.JOINED));
criteria.setMaxResults(10);
criteria.setFirstResult((paginate.getStartIndex()-1)*10);
criteria.setProjection(Projections.rowCount());
//here i need to fetch total row count and records

No comments:

Post a Comment