-->
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.  [ 5 posts ] 
Author Message
 Post subject: NOOB: limiting the max results returned by a query?
PostPosted: Sat Dec 03, 2005 1:51 pm 
Newbie

Joined: Fri Nov 25, 2005 4:44 pm
Posts: 12
Hi all, I'm just getting started with hibernate, and I am no DB expert...

Anyways the basic question is: Given A Query may return say 1 million rows, retrieving all 1 million records into a list..is obviously going to be memory issue. so..should the query result in in that many matching records, how can I specify a max return size?, and then or course continue the query later form the last record previous retrieved.

i.e. Doing:
Query q = session.createQuery("from BigMoFoTable");
List results = q.list();

could potentialy result in a list getting created with all the records?
(I'm assuming the list just wraps the JDBC ResultSet).

is there anyway to say do something along the lines of...

Query q = session.createQuery("from BigMoFoTable");
List results = q.list(MAX_SIZE);
.. DO WORK..
// Get the next 'batch' OF RESULTS
q.list(LAST_RESULT_SET_INDEX, MAX_SIZE);


THANX FOR ANY advice/tips, this noob will greatly appreciate it.


Top
 Profile  
 
 Post subject: Never Mind, (RTFM) found the anser in Hibernate in Action
PostPosted: Sat Dec 03, 2005 2:05 pm 
Newbie

Joined: Fri Nov 25, 2005 4:44 pm
Posts: 12
Chap 7, has the answer.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 3:50 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
why don't you use iterators? by the way you can set first result index and max number of results on query and criteria interfaces.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 5:51 pm 
Newbie

Joined: Fri Nov 25, 2005 4:44 pm
Posts: 12
actually have indeed started using iterators instead, the only downside it would be nice to the pass back the 'number' of potential results, when getting the iterator, I suppose I could do a getCount() type query if this was needed.

As of right now my plan is:

Use Lists for 'base data' type tables (and splice them into maps/lists) for quick jsp access.
Use iterators where the result sizes are unpredictable, and could be large..

Still need to read up hibernates caching stratgies, but I suspect it can cache 'iterators' accross sessions....

ps. anyone know of more upto date hibernate books than Hibernate in Action...(which Orielly had Hibernate book out)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 10:34 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
I strongly recommend that you download the hibernate source and hit breakpoints to see what is going on behind the scenes. There is no better learning tool that the source itself. Take a look at Loader.bindLimitParameters().

What you'll discover is that the limit/offset functionality is highly dependent upon your RDBMS, and you'll need to watchout for performance issues surrounding the availablity of these features and how your JDBC driver might compensate for them. For example, check out MS SQL Server, which has TOP, but no offset. This results in some client-side or server-side cursors that might not be too efficient, depending on the situation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.