Hibernate Criteria for Pagination

1k Views Asked by At

I am trying to fetch 10 rows or records per page using the Hibernate code as below,

List<?> sportsList = session
                        .createCriteria(SportsDAO.class)
                        .setFirstResult((Integer.valueOf(pageNo) - 1)* 10)
                        .setMaxResults(10)
                        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
                        .list();

But, the sportsList at times return only 3 values or lesser, even with more than 100 total records present in the Database.

What would be the change required in the above code to fetch 10 records based on Page Number (pageNo variable = 1, 2 , 3, etc..)

0

There are 0 best solutions below