This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Scrolling Results
 
Similar Threads
Hibernate optimization problem
Criteria
Controlling the display of JSP pages
Getting large result sets using hibernate
Question for the "Java Made Easy" book author