Alex Rivera | Logout

Implementing result paging in hibernate (getting total number of rows)

Asked 2009-10-21T11:22:50.990
11

How do I implement paging in Hibernate? The Query objects has methods called 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?

Edit
Report

1 Answer

17

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 2009-10-21T11:32:13.210

Your Answer