-->
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.  [ 2 posts ] 
Author Message
 Post subject: fetch="join" ignores lazy property?
PostPosted: Fri Aug 11, 2006 4:39 am 
Newbie

Joined: Mon Jan 17, 2005 8:11 pm
Posts: 1
On a mapped collection it seems fetch="join" ignores the lazy property and does indeed initialize the collection when the parent object is created.

For instance (on Hibernate 3.1.3):

mapping:
Code:
<class name="Parent">
..
<set name="children" inverse="true" fetch="join"  lazy="true">
..


DAO (via spring):
Code:
return (Parent) getHibernateTemplate().get(Parent.class, new Long(id));


The resulting query is:
Code:
..
FROM Parent LEFT OUTER JOIN child child1_ ON etc. etc.
..


Now it shouldn't fetch the child by default, only when I access the property in the session right? The problem isn't performance but later on in the same session I get a
Code:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session


is this a bug or am I overlooking something?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 9:14 am 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
When you join any relationship, the query includes the data for both the parent and child object, which disables lazy-loading. This is covered in the "tuning fetch strategies" section of the docs:

http://www.hibernate.org/hib_docs/v3/re ... ing-custom

You simply cannot have lazy-loading working with a joined relationship.

Ryan-[/quote]

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


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