According to my experience so far, criteria query with first/maxResults set is too slow!
Our construct for pagination:
1. create Hibernate Query object
Code:
Query q = getSession().createQuery("from MyEntity");
2. derive a ScrollableResults object
Code:
ScrollableResults scroll = q.scroll();
3. scroll to first result and build paging *manually* (no kidding, it's the fastest way, we found)
Code:
List result = new ArrayList();
scroll.first(); // <- about the necessity of this I'm not sure at the moment, might be ok to skip
scroll.scroll(startRow);
int i = 0;
while (i < rowsPerPage && scroll.next()) {
result.add(scroll.get(0));
i++;
}
Please notify me if you find out any more about this problem and performance regards.
Thanks.