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