Issue
How do I implement paging in Hibernate? The Query
objects has methods called href="https://www.hibernate.org/hib_docs/v3/api/org/hibernate/Query.html#setMaxResults(int)" rel="noreferrer">setMaxResults
and setFirstResult
which are certainly helpful. But where can I get the total number of results, so that I can show link to last page of results, and print things such as results 200 to 250 of xxx?
Solution
You can use Query.setMaxResults(int results) and Query.setFirstResult(int offset).
Editing too: There's no way to know how many results you'll get. So, first you must query with "select count(*)...". A little ugly, IMHO.
Answered By - sinuhepop
Answer Checked By - Pedro (JavaFixing Volunteer)