-->
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.  [ 6 posts ] 
Author Message
 Post subject: Why is Criteria.iterate() method missing ?
PostPosted: Thu Feb 17, 2005 5:36 am 
Newbie

Joined: Thu Feb 17, 2005 5:11 am
Posts: 1
Location: Brussels
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hello,

I am relatively new to hibernate, but I am very fond of it.
I have the following question that I don't seem to find in the documentation or in the FAQ's. Please forgive me if I am wrong.

I am using the Criteria class to dynamically compose ad-hoc queries. As I am expecting lots of result rows, I would like hibernate to produce result objects on demand, similar to what the Query.iterate() command is doing for HQL queries.
Unfortunately, the Criteria class only has a list() method, that fetches the complete result.
Can I do this some other way, or is there a reason why this is not possible ?

As an example, this is what I would - ideally - like to do :

Code:
Criteria crit = session.createCriteria(MyClass.class);
crit.add(Expression.eq("property", value);
// ... add more criteria
for (Iterator it = crit.iterate(); it.hasNext ; )
{
   MyClass myClass = (MyClass)it.next();
   // handle each result row on the fly
}


Meanwhile, I plan to add a createQuery() method to the Criteria class that produces an HQL query from the accumulated criteria, which would then allow me to perform an iteration.

Your help is greatly appreciated !
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 11:26 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
I have the same need. I worked around it using setFetchSize and setFirstResult and dealing with the results in chunks, but a lazy-load solution like iterate() would have been nicer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 11:30 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
rhasselbaum wrote:
I have the same need. I worked around it using setFetchSize and setFirstResult and dealing with the results in chunks, but a lazy-load solution like iterate() would have been nicer.


Oops. I meant to say setMaxResults, not setFetchSize. Although I must admit I'm not totally clear on the practical difference.

By the way, with this approach, the results must be ordered.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 6:36 pm 
Newbie

Joined: Tue Jul 20, 2004 2:40 pm
Posts: 9
Location: New York, NY
I am currently working with the Criteria API quite a bit, and this stood out as a big red flag to me, as well. The lack of ability to utilize the 2nd-level cache is a definite issue, and I don't see how the people who are currently using the Criteria API haven't been bringing this up more often.

I see that there is a JIRA open for this:

http://opensource2.atlassian.com/projec ... se/HHH-249

However, it's marked as 'Minor' priority, and doesn't look as if it's been touched since it was opened in March. I assume that this means this feature will not be included with H3.1.

Judging from the documentation, CaveatEmptor, and the forums, it seems that the Criteria API is the direction that Hibernate developers are being pointed in for ongoing development. Without the ability to pull objects from the cache, is using the Criteria API a viable option for any query that may potentially be pulling back sizeable numbers of large objects?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There's another issue in JIRA for it, HHH-308 (with entertaining comment by Christian :). Not that it's much more "active"... :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:30 pm 
Newbie

Joined: Tue Jul 20, 2004 2:40 pm
Posts: 9
Location: New York, NY
tenwit wrote:
There's another issue in JIRA for it, HHH-308 (with entertaining comment by Christian :). Not that it's much more "active"... :(



hanks for the tip! =) ...actually, it's HB-308:

http://opensource2.atlassian.com/projec ... wse/HB-308


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