I have the following business classes Deal and Instrument, a deal has only one instrument and I want to allow an Instrument to reference it's parent deal.
I'm using the following mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DealBusinessComponents.Instrument, DealBusinessComponents"
table="DEA_INSTRUMENT">
<id name="Id" column="ITR_ID" type="Int32" unsaved-value="0">
<generator class="sequence">
<param name="sequence">ITR_SEQ</param>
</generator>
</id>
<discriminator column="ITR_TP" />
<property name="UpdateDate" column="ITR_LASTUPD" type="DateTime" />
<property name="DeleteDate" column="ITR_DTDELETE" type="DateTime" />
<many-to-one name="Deal" class="DealBusinessComponents.Deal, DealBusinessComponents" column="ITR_ID_DEA" outer-join="true"/>
</class>
<class name="DealBusinessComponents.Deal, DealBusinessComponents" table="DEA_DEAL" where="DEA_DTDELETE = to_date('01013000', 'ddmmyyyy')">
<id name="Id" column="DEA_ID" type="Int32" unsaved-value="0">
<generator class="sequence">
<param name="sequence">DEA_SEQ</param>
</generator>
</id>
<discriminator column="DEA_TP" />
<property name="UpdateDate" column="DEA_LASTUPD" type="DateTime"/>
<property name="DeleteDate" column="DEA_DTDELETE" type="DateTime"/>
<one-to-one name="Instrument" class="DealBusinessComponents.Instrument, DealBusinessComponents" outer-join="false" cascade="all" property-ref="Deal"/>
</class>
When running the following HQL:
Code:
from Instrument instrument join instrument.Deal deal where deal is not null order by deal.Id desc
Nhibernate generates one select to return all instruments and their joined deal, and again one select per instrument.
Is this behavior normal? Is there a way to avoid the n unuseful selects?