This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

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.

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

Page 1:
criteria.setMaxResults(50);
criteria.setFirstResult(0);

Page 2:
criteria.setMaxResults(50);
criteria.setFirstResult(50);

etc

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.

Thanks,
Paul Croarkin


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

Joined: Jul 20, 2005
Posts: 292

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?
 
GeeCON Prague 2014
 
subject: Hibernate Scrolling Results