-->
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: bidirectional one-to-one causes n+1 select with runing hql
PostPosted: Wed Nov 23, 2005 8:50 am 
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?


Top
  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 9:35 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
If you can avoid property-ref, it will solve the problem. Property-refs are less efficient in general because NHibernate does not track entities by their property-ref values.


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.