File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate Scrolling Results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Scrolling Results" Watch "Hibernate Scrolling Results" New topic

Hibernate Scrolling Results

Paul Croarkin
Ranch Hand

Joined: Sep 30, 2004
Posts: 106
Some databases and/or drivers do not support scrollable result sets. I've found a way to manage the scrolling myself using the Criteria interface.

Image that there are 5000 rows that match your select statement, but you only want to display 50 at a time.

Page 1:

Page 2:


My question: Is this the best way to handle results scrolling when the db/driver does not support it directly, or is there another approach.

Paul Croarkin

Thanks,<br /> <br />Paul Croarkin<br />SCEA 5, SCWCD, SCJP
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

Using scrollable result sets can have adverse performace effects on your database, particularly when it is under heavy load.

I prefer to use a Value List Handler in these situations.
Paul Croarkin
Ranch Hand

Joined: Sep 30, 2004
Posts: 106
OK, fair enough. Now, how do implement it using Hibernate?

It seems to me that the ValueListHandler could use Hibernate Criteria queries with setMaxResults and setFirstResult in the getNextElements(int count) and getPreviousElements(int count) methods.

Is there a better way in Hibernate to do this?
I agree. Here's the link:
subject: Hibernate Scrolling Results
It's not a secret anymore!