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.  [ 7 posts ] 
Author Message
 Post subject: iterator for Criteria API
PostPosted: Fri Oct 17, 2003 5:15 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 6:11 pm
Posts: 34
Is it possible to get an iterator for a query created
using the criteria API ?

I want to use the criteria API to process large result sets


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2003 9:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, it is not yet possible. Don't expect this before Hibernate 2.2.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 5:00 pm 
Newbie

Joined: Fri Oct 12, 2007 12:23 pm
Posts: 9
Has this been added? I have a requirement to export massive amounts of data as a CSV, and am already using the Criteria API. It would be swell if I could stream the results out using an iterator, rather than having to wait until a whole list is 100% populated. Thanks!
--Corey


Top
 Profile  
 
 Post subject: Yup it's in there
PostPosted: Mon Apr 21, 2008 7:47 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
Code:
Iterator itr = criteria.list().iterator();
....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 5:40 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
yes

criteria.scroll(ScrollMode.FORWARD_ONLY)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 10:00 am 
Newbie

Joined: Fri Oct 12, 2007 12:23 pm
Posts: 9
steppinrazor: While .list().iterator does get me an iterator, it forces Hibernate to fully load the backing list before I can iterate through the first one. This is fine for small datasets, but for large ones (say, millions of rows), this could really be a drain on system memory.

ferozz: This is exactly what I was looking for. I guess I missed it since I was looking for a method called "iterate", not "scroll".

Thanks for both of your help!
--Corey


Top
 Profile  
 
 Post subject: Asolutely correct
PostPosted: Tue Apr 22, 2008 1:59 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
Hibernate does load the entire result set before you get the iterator. In addition to Ferozz's input you can also get an iterator like this:

Code:
Query q = session.createQuery("from X x where x.name like :name");
q.setString("name",name);
Iterator i = q.iterate();


This however only returns the ids and not the entire object until you iterate, then a select is generated to retrieve all the columns. In certain circumstances this can be a good optimization (as usually optimization is associated with minimal row return).

Could you and Ferozz look at something that I posted that no one has replied to and let me know what you guys think http://forum.hibernate.org/viewtopic.php?t=986008


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