Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Scrolling Results

 
Paul Croarkin
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Salter
Ranch Hand
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic