You can set the limit for get the result which is returned by the query by calling the function query.setMaxResults()
and toy can set the start position for your query result.
Query query = session.createQuery("from PostMessageUsers as pmu left join fetch pmu.postMessages as pm left join fetch pm.comments as cmts
where pmu.atomByReceivedBy.id=1 oder by commentDate desc");
query.setFirstResult(0);
query.setMaxResults(5);
List result = query.list();
It will return the result of the query with 5th results starting from 1 record.
i.e. 1 to 5 records.
Or
Query query = session.createQuery("from PostMessageUsers as pmu left join fetch pmu.postMessages as pm left join fetch pm.comments as cmts
where pmu.atomByReceivedBy.id=1 oder by commentDate desc");
query.setFirstResult(5);
query.setMaxResults(5);
List result = query.list();
It will return the result of the query with 5 results starting from 6th record.
i.e. 6 to 10 records.
and if you want to details example with details follow this link
Hibernate Pagination Example
and if you are using Criteria Queries
then follwo the this link
Criteria Queries In Hibernate
Thanks...