-->
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.  [ 8 posts ] 
Author Message
 Post subject: left join fetch on composite-id component properties
PostPosted: Thu Oct 06, 2005 8:35 pm 
Hi!

I have an object model that looks like this:
class ClassA has a composite id UniqueId=(ClassB, ClassC), both B and C being many to one.

<class name="ClassA" ...>
<composite-id name="Id" class="UniqueId" ...>
<key-many-to-one name="B" class="ClassB" .../>
<key-many-to-one name="C" class="ClassC" .../>
</composite-id>
.....
</class>

Executing query "from ClassA a" results in b + c + 1 trips to the database, where b is the number of unique B objects, similar for C.

I tried running "from ClassA a left join fetch a.Id.B left join fetch a.Id.C" but even though the first statement retrieves all the data that it needs, it still goes to the db b + c more times, and retrieves the B and C objects again.

Am i doing something wrong or is this a bug?

Thanks,
Cris


Top
  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 3:24 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
i have the exact same behaviour and i do not see why this should be.

The first query does this:

Code:
NHibernate :select persoon0_.SubjectNr as SubjectNr0_, inkomens1_.SUBJECTNR as SUBJECTNR1_, inkomens1_.SUBJECTNRWERKG as SUBJECTN2_1_, inkomens1_.SOORT as SOORT1_, inkomens1_.Periodiciteit as Periodic4_1_, inkomens1_.categorie as categorie1_, inkomens1_.SubjectNr as SubjectNr__, inkomens1_.SUBJECTNR as SUBJECTNR__, inkomens1_.SUBJECTNRWERKG as SUBJECTN2___, inkomens1_.SOORT as SOORT__, inkomens1_.Periodiciteit as Periodic4___ from personen persoon0_ inner join inkomens inkomens1_ on persoon0_.SubjectNr=inkomens1_.SubjectNr where (inkomens1_.categorie=4)or(inkomens1_.SOORT=110)


then I see thousands of calls:
Code:
NHibernate :SELECT persoon0_.SubjectNr as SubjectNr0_ FROM personen persoon0_ WHERE persoon0_.SubjectNr = :p0

(which seem useless :evil: )

then again thousands of calls:
Code:
NHibernate :SELECT periods0_.Subjectnr as Subjectnr__, periods0_.SUBJECTNRWERKG as SUBJECTN2___, periods0_.SOORT as SOORT__, periods0_.Periodiciteit as Periodic4___, periods0_.SUBJECTNR as SUBJECTNR__, periods0_.TijdslijnID as Tijdslij5___, periods0_.SUBJECTNR as SUBJECTNR1_, periods0_.SUBJECTNRWERKG as SUBJECTN2_1_, periods0_.SOORT as SOORT1_, periods0_.Periodiciteit as Periodic4_1_, periods0_.TijdslijnID as Tijdslij5_1_, periods0_.Categorie as Categorie1_, periods0_.Dtafvoer as Dtafvoer1_, periods0_.Dtopvoer as Dtopvoer1_, periods0_.Status as Status1_, periods0_.Dteinde as Dteinde1_, periods0_.Dtbegin as Dtbegin1_, periods0_.Geldig as Geldig1_, periods0_.SubjectNr as SubjectNr1_, periods0_.Afgeleid as Afgeleid1_, periods0_.BedragNetto as BedragN15_1_, periods0_.BedragBruto as BedragB16_1_, periods0_.BelastbaarLoon as Belastb17_1_, periods0_.Kleur as Kleur1_, periods0_.BijzonderTarief as Bijzond19_1_, periods0_.ReserveringVT as Reserve20_1_, periods0_.kenmerkwerkg as kenmerk21_1_, periods0_.HeffingsKorting as Heffing22_1_, periods0_.Kenmerkwerkg as Kenmerk23_1_, periods0_.hoogte as hoogte1_, inkomen1_.SUBJECTNR as SUBJECTNR0_, inkomen1_.SUBJECTNRWERKG as SUBJECTN2_0_, inkomen1_.SOORT as SOORT0_, inkomen1_.Periodiciteit as Periodic4_0_, inkomen1_.categorie as categorie0_ FROM inkomen periods0_ left outer join inkomens inkomen1_ on periods0_.SubjectNr=inkomen1_.SUBJECTNR and periods0_.SUBJECTNRWERKG=inkomen1_.SUBJECTNRWERKG and periods0_.SOORT=inkomen1_.SOORT and periods0_.Periodiciteit=inkomen1_.Periodiciteit WHERE periods0_.Subjectnr = :p0 AND periods0_.SUBJECTNRWERKG = :p1 AND periods0_.SOORT = :p2 AND periods0_.Periodiciteit = :p3 and periods0_.status > -2


It seems this could have been alot more efficient. I'm using Oracle9 dialect and outer-joining is not disabled.
Is there something that could be done about this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 4:54 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You probably don't have proxies enabled for B and C, that's why NH goes a bit crazy about the key-many-to-one's.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 8:12 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
sergey wrote:
You probably don't have proxies enabled for B and C, that's why NH goes a bit crazy about the key-many-to-one's.


lazy is set to true and they are both bags


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 10:27 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
TheShark wrote:
lazy is set to true and they are both bags

I was replying to the <key-many-to-one> issue the original poster had. In your case I would need to see the mappings to give any advice.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 12:05 pm 
Cool, I have enabled proxies and it works now.

Is this always going to be a requirement, or is it just a temporary issue?

Got a 6-pack in the fridge!
Thanks,
Cris


Top
  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 4:54 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
sergey wrote:
TheShark wrote:
lazy is set to true and they are both bags

I was replying to the <key-many-to-one> issue the original poster had. In your case I would need to see the mappings to give any advice.


Sorry :roll:
definition of a person:
Code:
   <class name="DomainModel.Persoon.Persoon, DomainModel" table="personen" mutable="false">

      <composite-id name="Identity" class="DomainModel.Persoon.PersoonKey, DomainModel" unsaved-value="none">
         <key-property name="SubjectNr" type="Int32" />
      </composite-id>
      
      <bag name="Periods" inverse="true" lazy="false" cascade="all-delete-orphan"  where="status > -2">
         <key column="SubjectNr" />
         <one-to-many class="DomainModel.Persoon.PersoonPeriod, DomainModel" />
      </bag>

      <bag name="Inkomens" lazy="true" inverse="true" cascade="none" access="field.camelcase" >
         <key column="SubjectNr" />
         <one-to-many class="DomainModel.Inkomen.Inkomen, DomainModel" />
      </bag>
      

      
   </class>


definition of an income (inkomen)
Code:
   <class name="DomainModel.Inkomen.Inkomen, DomainModel" table="inkomens" mutable="false" >

      <composite-id name="Identity" class="DomainModel.Inkomen.InkomenKey, DomainModel" unsaved-value="none">
         <key-many-to-one name="Klant" class="DomainModel.Persoon.Persoon, DomainModel" column="SUBJECTNR" />
         <key-many-to-one name="Werkgever" class="DomainModel.Persoon.Persoon, DomainModel" column="SUBJECTNRWERKG" />
         <key-property name="InkomenSoort" type="DataFramework.Types.RefitemType, DataFramework" column="SOORT" />
         <key-property name="Periodiciteit" type="DataFramework.Types.RefitemType, DataFramework" />
      </composite-id>
      
      <property name="categorie" access="field" />
      
      <bag name="Periods" inverse="true" lazy="false" cascade="all-delete-orphan" where="status > -2">
         <key>
            <column name="Subjectnr" />
            <column name="SUBJECTNRWERKG" />
            <column name="SOORT" />
            <column name="Periodiciteit" />
         </key>
         <one-to-many class="DomainModel.Inkomen.baseInkomenPeriod, DomainModel" />
      </bag>
   
      
   </class>


Got a 6-pack as well :?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 11:35 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I have created a Jira for this with a ready to go test

http://jira.nhibernate.org/browse/NH-517


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.