-->
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: Does outer-join attribute have any impact on HQL queries
PostPosted: Fri Sep 09, 2005 6:28 am 
Could anyone confirm if many-to-one associations should be resolved by Nhibernate using a single query with joins when outer-join is set to true?

To make it clear, I have the following simple mapping:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
      <class name="SimpleTest.Deal, SimpleTest" table="DEA_DEAL">
      <id name="DealID" column="DEA_ID" type="Int32" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">DEA_SEQ</param>
         </generator>
      </id>
      <property name="Date" type="DateTime" column="DEA_DT" />
            <many-to-one name="AccountingPortfolio" class="SimpleTest.Portfolio, SimpleTest"
         column="DEA_ID_APRF" outer-join="true"/>
      <many-to-one name="TradingPortfolio" class="SimpleTest.Portfolio, SimpleTest"
         column="DEA_ID_TPRF" outer-join="true"/>
      <many-to-one name="Instrument" class="SimpleTest.GenericInstrument, SimpleTest" column="DEA_ID" outer-join="true"/>
   </class>
   <class name="SimpleTest.GenericInstrument, SimpleTest" table="DEA_INSTRUMENT">
      <id name="InstrumentID" column="ITR_ID" type="Int32" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">ITR_SEQ</param>
         </generator>
      </id>
            <many-to-one name="TradingPortfolio" class="SimpleTest.Portfolio, SimpleTest"
         column="ITR_ID_TPRF" />
      <bag name="InstrumentSequence" inverse="false" lazy="true" order-by="ITR_ID" where="ITR_DTDELETE = to_date('01013000', 'ddmmyyyy')" >
         <key column="ITR_ID_ITR" />
         <one-to-many class="SimpleTest.GenericInstrument, SimpleTest"/>
      </bag>
   </class>
      <class name="SimpleTest.Portfolio, SimpleTest" table="PTF_PORTFOLIO" where="PTF_DTDELETE = to_date('01013000', 'ddmmyyyy')" mutable="false">
      <id name="Id" column="PTF_ID" type="Int32" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">PRF_SEQ</param>
         </generator>
      </id>
      <property name="Code" type="String" column="PTF_CD" />
      <property name="Name" type="String" column="PTF_NAME" />
      <property name="DeleteDate" column="PTF_DTDELETE" type="DateTime"/>
      <property name="UpdateDate" column="PTF_LASTUPD" type="DateTime"/>
   </class>
</hibernate-mapping>


when I run the following HQL: "from Deal"
I would expect the portfolio and instrument to be loaded in a single select, but nhibernate keeps running several selects to resolve the many-to-one associations. Is that a normal behavior?


Top
  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:38 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
From Hibernate FAQ:
Quote:
Hibernate ignores my outer-join="true" setting and fetches an association lazily, using n+1 selects!

HQL queries always ignore the setting for outer-join defined in the mapping document. This setting applies only to associations fetched using get() or load(), Criteria queries, and graph navigation. If you need to enable eager fetching for a HQL query, use an explicit LEFT JOIN FETCH.

Note also that Hibernate 2.x does not support outer join fetching of more than one many-valued association in the same query. Hibernate 3.x allows you to create Cartesian products, even if they are slower than two separate queries.


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.