-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to know if setMaxResults actually limited the result
PostPosted: Mon Jan 17, 2005 6:47 am 
Newbie

Joined: Mon Jan 17, 2005 6:22 am
Posts: 2
Hibernate version 2.1.7

If I use setFirstResult and setMaxResults to perform pagination in a web application, how can I tell if I reached the last result from a query b/c there were no more records in the database or b/c I reached maxResults. I'm looking for a method something like waslimitedByMaxRows() just like one would have available in the jstl api for javax.servlet.jsp.jstl.sql.Result.

I suppose one could do an sql count to see how many records actually exist. Or when maxResults is reached one could do a second query with setMaxResult(1) and setFirstResult(startRow+maxResults) and if this returns a list greater then zero one would know that the previous query was limited by setMaxResults.

Thanks,
Jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
if (resultSize < max) {
  //end of the results
}

Works in (max-1)/max cases

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 12:18 am 
Newbie

Joined: Mon Jan 17, 2005 6:22 am
Posts: 2
I guess I was looking for the works 100% of the time solution. So that I wouldn't display a "next" link to the user for the next set of results unless there really were more results. However, I guess it really isn't necessary since most of the time or as you say "(max-1/max)" of the time you will know that the results are finished by the results found being less than max.

Perhaps someday a limitedByMaxResults method could be implemented in net.sf.hibernate.collection.PersistentCollection or net.sf.hibernate.Collection.

Thanks for your help,
Jason


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 10:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actially you can do setMaxResults(max+1) and display only max result, you can then play with it the limit

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.