File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate Scrolling Results
 
Similar Threads
Question for the "Java Made Easy" book author
Getting large result sets using hibernate
Criteria
Hibernate optimization problem
Controlling the display of JSP pages