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.  [ 1 post ] 
Author Message
 Post subject: Strange SQL generated on 1:1 mapping
PostPosted: Mon Mar 05, 2007 4:05 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
I'm using NHibernate 1.0.4 and SQL-Server 2000.

While doing some perfomance analysis on my code i inspected the SQL generated by NHibernate for the following mapping (i have simplified it because there are many fields in the tables):

Code:
<class name="GdcMaterial" table="GDC_MATERIAL">
   <id name="mId" column="MATERIAL_ID" access="field" type="Guid">
      <generator class="guid"/>
   </id>
   <many-to-one name="Autopull" column="AUTOPULL_ID" class="GdcAutopull" unique="true" cascade="all-delete-orphan" />
   ... further field definitions ...
</class>

<class name="GdcAutopull" table="GDC_AUTOPULL">
   <id name="mId" column="AUTOPULL_ID" access="field" type="Guid">
      <generator class="guid"/>
   </id>
   <many-to-one name="OptionalAutopull" column="OPTIONAL_AUTOPULL_ID" class="GdcOptionalAutopull" unique="true" cascade="all-delete-orphan" />
   <one-to-one name="Material" class="GdcMaterial" property-ref="Autopull" />
... further field definitions ...
</class>

<class name="GdcOptionalAutopull" table="GDC_OPTIONAL_AUTOPULL">
   <id name="mId" column="OPTIONAL_AUTOPULL_ID" access="field" type="Guid">
      <generator class="guid"/>
   </id>
   <one-to-one name="Autopull" class="GdcAutopull" property-ref="OptionalAutopull" />
... further field definitions ...
</class>


If i try to read GdcOptionalAutopull instances, NHibernate generates the following SQL:

Code:
SELECT
   ... field names ...
FROM
   GDC_OPTIONAL_AUTOPULL this
   left outer join GDC_AUTOPULL gdcautopul1_ on this.OPTIONAL_AUTOPULL_ID=gdcautopul1_.OPTIONAL_AUTOPULL_ID
   left outer join GDC_MATERIAL gdcmateria2_ on gdcautopul1_.AUTOPULL_ID=gdcmateria2_.AUTOPULL_ID
   left outer join GDC_OPTIONAL_AUTOPULL gdcoptiona3_ on gdcautopul1_.OPTIONAL_AUTOPULL_ID=gdcoptiona3_.OPTIONAL_AUTOPULL_ID


Did anyone have an idea why NHibernate generates the third join ?

Regards
Klaus


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.