0

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..)

Harish
  • 181
  • 1
  • 3
  • 11
  • is that the complete query? Or are you using something that contains a join? Cause if you use a joined query, you will receive 10 rows, which are then reduced by your result-transformer to only contain distinct root entities. the result transformer is executed "POST-SQL", so the number of rows will be always <= the rows you actually queried. – dognose Nov 26 '14 at 18:18
  • This table has a ManyToMany mapping with another table. And I have 100 distinct records. – Harish Nov 26 '14 at 18:22
  • Give the whole method from creation to running of `Criteria` . – Junaid Nov 26 '14 at 20:06

0 Answers0