gtludwig gtludwig - 1 year ago 57
Java Question

Hibernate pagination - how to get the next batch of results?

I understand pagination to improve performance on queries that, naturally, have a very large resultset.

I have the implemented paginatedList method that successfully returns the correct amount. But it seems more of a MySQL's

or SQLServer's

The method is thus implemented:

public List<T> paginatedList(int pageSize) {
Criteria criteria = getSession().createCriteria(persistentClass);
return (List<T>) criteria.list();

And I call like this:

public List<AlertLog> findAll() {
return super.paginatedList(1000);

This implementation returns results 0 to 1000.

How to, on runtime, get the 1001st to 2000th and so on?

Answer Source

to get the next 1000 result you need to set firstResult to 1000 and maxresults to 1000, so it becomes..


Please make sure that the noOfEntries is less that the total count.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download