-->
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: Lazy One to One
PostPosted: Sun Sep 11, 2005 9:11 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I have a one to one relationship from one object to another(Member to JobPost). Both objects have the lazy attribute so they can be proxied.

When I query for the Member object an additional sql query is issued immediatly to load the JobPost which is specified as the one-to-one. Are my settings wrong? Is this a bug? I have abbreviated the mappings and listed them below.

Code:
<class name="Member" table="Member" lazy="true">
      <!--ID-->
      <id name="Id" column="MemberId" unsaved-value="0" access="nosetter.camelcase-underscore">
         <generator class="identity" />
      </id>
            
      
      <!--ASSOSCIATIONS-->
      <one-to-one name="JobPost" class="JobPost"  property-ref="StaffMember" access="nosetter.camelcase-underscore"  outer-join="true"  />
         
   </class>

<class name="JobPost" table="JobPost" lazy="true">      
      <!--ID-->
      <id name="Id" column="JobPostId" unsaved-value="0" access="nosetter.camelcase-underscore">
         <generator class="identity" />
               
      <!--ASSOSCIATIONS-->
      <many-to-one name="StaffMember" column="MemberId" class="Member"  access="nosetter.camelcase-underscore"  outer-join="true" unique="true" />
            
   </class>



Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 9:27 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Sorry, but actually in the mapping file above I have outer-join set to true. I was testing something at the time that I copied the mapping. The problem I am experiencing is occurring when the outer-join on the one to one mapping is false. Sorry about that. The actual mapping is listed below.

Code:
<one-to-one name="JobPost" class="JobPost"  property-ref="StaffMember" access="nosetter.camelcase-underscore"  outer-join="false"  />


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 3:59 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate won't use lazy-loading for one-to-one relationship, unless it has constrained="true", meaning the referenced object always exists. Otherwise, NHibernate needs to find out whether the object exists, to know whether to set the reference to null or to create a proxy for the object, and since it has to SELECT from a table to find that out, it can as well get the entire object data with that SELECT. NH assumes that selecting 10 fields from a table is about as expensive as selecting only one.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 4:34 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Setting constrained="true" has no effect.

Atleast, since the one to one is a simple assosciation shouldnt it be able to be queried without having to issue a separate sql query?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 5:49 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This page should give you more and better details: http://www.hibernate.org/162.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 12:45 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Hmm, I guess this topic actually describes the problem: http://nhibernate.sourceforge.net/forum/viewtopic.php?p=2545


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 1:33 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Ok. So apparently it cant be lazy loaded. This still doesn't explain why an additional select statement is getting issued for the object. Its one to one so it should be coming down in one query right?


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.