-->
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: What's the difference between createQuery() and find() ?
PostPosted: Wed Dec 03, 2003 9:23 am 
Newbie

Joined: Mon Nov 10, 2003 7:39 pm
Posts: 8
I'm evaluating hibernate and trying to figure out is it suitable for me or not. I've tried to execute "select bean from table_name as bean" query using session.createQuery() and session.find() methods and i've found that createQuery() method executes 1 select for all PKs and then N selects to pupulate beans but find() method calls DB only one time for the same query. What's is the difference?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 9:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
session.iterate() and query.iterate() do the N+1 stuff
session.find() and query.list() do 1 request

the find stuff won't look at the cache
the iterate stuff load the pks and lokk at the cache for each asked object before lokking to in the db.

Have a look at the javadoc and the reference guide for more info.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 10:55 am 
Newbie

Joined: Mon Nov 10, 2003 7:39 pm
Posts: 8
Does find() method update the cache with the loaded objects? and what could be a reason to use session.iterate() due to N+1 problem?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Does find() method update the cache with the loaded objects?


yes.


Quote:
and what could be a reason to use session.iterate() due to N+1 problem?


if you expect the objects to be in the cache


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.