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: Paginated Queries
PostPosted: Fri Jul 15, 2005 11:58 pm 
Newbie

Joined: Thu May 19, 2005 11:50 pm
Posts: 10
I want to run a query that returns 10 results per page. I know I can use "setFirstResult" and "setMaxResults" to get the items for the current page. But, I also want to display to the user "page x of y of z results". I know x is the current page. Y can be calculated if I knew Z. I can figure out Z by re-running my query using a the count feature. However, that means I have to run several queries to get the data to the end user. Is there any elegant way to handle this type of thing to prevent multiple calls to the DB?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 16, 2005 7:24 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
If you can do it in SQL you can do it in HQL...

What would be the SQL way?

It depends if the list is updated frequenly or not. I dont know the best way to do it, but you can cache the result if it not too heavy, cache only the ids, or make a count one time and modify the HQL to navigate in the result list... (remember only the last id of the 10th element), or make a count each time and reajust the query, if the list can change each minute...

It depends of the kind of search engine you want.

Etienne.


Top
 Profile  
 
 Post subject: Not Sure The Correct SQL Way
PostPosted: Sun Jul 17, 2005 5:53 am 
Newbie

Joined: Thu May 19, 2005 11:50 pm
Posts: 10
I'm not sure what the correct SQL way would be actually. If I make this 2 queries then there's a chance the 2nd query will return more or less results than the 1st query.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 17, 2005 9:24 am 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Then make only one query to have the total of search result and the complete Ids of them, save it in a http session and browse them after.

I am not sure it is a "best practice", anyway. It seems to be a business problem not a hibernate one.


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.