-->
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: one-to-one lazy initialization doesn't work
PostPosted: Sat Feb 02, 2008 6:13 pm 
Newbie

Joined: Mon Mar 27, 2006 7:46 pm
Posts: 17
I can't get any of my one-to-one mappings that are foreign keys with a unique constraint to lazily initialize. These are mostly situations where the referenced object can be null.

Here is an example mapping for the classes customer and spouse. A customer may or may not have a spouse but if the customer does there is only one:

From the Customer mapping:
Code:
        <one-to-one name="spouse" class="Spouse" property-ref="customer" cascade="all"  access="field" lazy="proxy"/>


From the Spouse mapping:
Code:
        <many-to-one name="customer" class="Customer" unique="true"
                     access="field" not-null="true" column="customer_id" cascade="none" lazy="proxy"/>


Every time I get the customer it loads the spouse if there is one. This creates a pretty significant performance hit if i load a bunch of customers at once. I have experimented with the lazy setting and the constrained="true" setting and neither seem to have an effect.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 6:42 pm 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
Here's a good link explaining the problem with lazy one-to-one mappings, and in particular when the association is not mandatory (ie may be null):

http://www.hibernate.org/162.html#A3


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.