-->
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.  [ 11 posts ] 
Author Message
 Post subject: Eager loading of "one-to-one" association
PostPosted: Wed May 04, 2005 9:18 am 
Newbie

Joined: Wed May 04, 2005 9:01 am
Posts: 5
Hibernate version: 2.1.8

Problem description:
I have a problem concerning a "one-to-one" association. I have not been able to figure out how to tell Hibernate to load the association along with the owner objects, i.e. I want to make an eager load of the association using a left join fetch. Debugging through Hibernate, I see that the SQL is as I would suppose, and it loads both my owner object and the associated object. However - when I reach the method <code>initializeEntitiesAndCollections</code> on Loader.java for the main object - Hibernate makes a new sql on the relating table. This it does for each row in the resultset, i.e. for 10 owner objects it would result in 11 sql-statements.

What am I doing wrong here ??

Mapping documents:

Main class:
<class
name="dk.mlon.appmoduler.medarbejder.impl.MedarbejderAkkordDO"
schema="h7805"
table="medarb"
dynamic-insert="true"
dynamic-update="true"
>

<one-to-one
name="fritvalg"
class="dk.mlon.appmoduler.medarbejder.impl.FritvalgDO"
property-ref="medarbejder"
outer-join="false"
constrained="true"
cascade="all"/>
</class>

Associated class:

<class
name="dk.mlon.appmoduler.medarbejder.impl.FritvalgDO"
schema="h7805"
table="fritvalg"
dynamic-insert="true"
dynamic-update="true"
lazy="true"
>

<many-to-one
name="medarbejder"
class="dk.mlon.appmoduler.medarbejder.impl.MedarbejderAkkordDO"
outer-join="false"
column="m25medarbide"/>



Name and version of the database you are using: DB2 for Z-os version 8.

The generated SQL (show_sql=true):

In the example below, I select one owning object and along with that the associated object. However it results in 2 sql-statements.

Hibernate: select medarbejde0_.m20objektid as m20objek1_0_, fritvalgdo1_.m25objektid as m25objek1_1_, medarbejde0_.m20opdtv as m20opdtv0_, medarbejde0_.m20samleobjid as m20samle3_0_, medarbejde0_.m20edb as m20edb0_, medarbejde0_.m20arb as m20arb0_, medarbejde0_.m20versionsid as m20versi6_0_, medarbejde0_.m20erudgaet as m20erudg7_0_, medarbejde0_.m20prod as m20prod0_, medarbejde0_.m20titel as m20titel0_, medarbejde0_.m20conavn as m20conavn0_, medarbejde0_.m20navn as m20navn0_, medarbejde0_.m20gade as m20gade0_, medarbejde0_.m20postnr as m20postnr0_, medarbejde0_.m20by as m20by0_, medarbejde0_.m20natadresse as m20nata15_0_, medarbejde0_.m20cprnr as m20cprnr0_, medarbejde0_.m20fodsdato as m20fods17_0_, medarbejde0_.m20cprlobenr as m20cprl18_0_, medarbejde0_.m20tlfnr as m20tlfnr0_, medarbejde0_.m20mobiltlf as m20mobi20_0_, medarbejde0_.m20emailadr as m20emai21_0_, medarbejde0_.m20bank1 as m20bank10_, medarbejde0_.m20kontonr1 as m20kont23_0_, medarbejde0_.m20bank2 as m20bank20_, medarbejde0_.m20kontonr2 as m20kont25_0_, medarbejde0_.m20pensionkd as m20pens26_0_, medarbejde0_.m20ancidato as m20anci27_0_, medarbejde0_.m20datoaranc as m20dato28_0_, medarbejde0_.m20til0fratr as m20til029_0_, medarbejde0_.m20afspads as m20afspads0_, medarbejde0_.m20modetid as m20modetid0_, medarbejde0_.m20longrp as m20longrp0_, medarbejde0_.m20udbetsted as m20udbe33_0_, medarbejde0_.m20organisa as m20orga34_0_, medarbejde0_.m20arbsted as m20arbsted0_, medarbejde0_.m20hel0del as m20hel0del0_, medarbejde0_.m20skfthold as m20skft37_0_, medarbejde0_.m20morgenpa as m20morg38_0_, medarbejde0_.m20kommune as m20kommune0_, medarbejde0_.m20grpliv as m20grpliv0_, medarbejde0_.m20sh0opspa as m20sh0o41_0_, medarbejde0_.m20atp as m20atp0_, medarbejde0_.m20timelont as m20time43_0_, medarbejde0_.m20normalti as m20norm44_0_, medarbejde0_.m20belob as m20belob0_, medarbejde0_.m20indi0time as m20indi46_0_, medarbejde0_.m20fast0lon as m20fast47_0_, medarbejde0_.m20kapp0pct as m20kapp48_0_, medarbejde0_.m20kapp0kr as m20kapp0kr0_, medarbejde0_.m20pct0supen as m20pct050_0_, medarbejde0_.m20nationalitet as m20nati51_0_, medarbejde0_.m20anvferiekort as m20anvf52_0_, medarbejde0_.m20ambfritag as m20ambf53_0_, medarbejde0_.m20deltid as m20deltid0_, medarbejde0_.m20fridafri as m20frid55_0_, medarbejde0_.m20landekd as m20landekd0_, medarbejde0_.m20arbstedund as m20arbs57_0_, medarbejde0_.m20logon as m20logon0_, medarbejde0_.m20retdato as m20retdato0_, fritvalgdo1_.m25opdtv as m25opdtv1_, fritvalgdo1_.m25edb as m25edb1_, fritvalgdo1_.m25prod as m25prod1_, fritvalgdo1_.m25udbetandel as m25udbet5_1_, fritvalgdo1_.m25pensionandel as m25pensi6_1_, fritvalgdo1_.m25fridagandel as m25frida7_1_, fritvalgdo1_.m25glordn as m25glordn1_, fritvalgdo1_.m25medarbide as m25medar9_1_ from h7805.medarb medarbejde0_ left outer join h7805.fritvalg fritvalgdo1_ on medarbejde0_.m20objektid=fritvalgdo1_.m25medarbide where (medarbejde0_.m20edb=999 )and(medarbejde0_.m20prod=2304 )and(medarbejde0_.m20arb=10 )

Hibernate: select fritvalgdo0_.m25objektid as m25objek1_0_, fritvalgdo0_.m25opdtv as m25opdtv0_, fritvalgdo0_.m25edb as m25edb0_, fritvalgdo0_.m25prod as m25prod0_, fritvalgdo0_.m25udbetandel as m25udbet5_0_, fritvalgdo0_.m25pensionandel as m25pensi6_0_, fritvalgdo0_.m25fridagandel as m25frida7_0_, fritvalgdo0_.m25glordn as m25glordn0_, fritvalgdo0_.m25medarbide as m25medar9_0_ from h7805.fritvalg fritvalgdo0_ where fritvalgdo0_.m25medarbide=?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 7:17 am 
Beginner
Beginner

Joined: Thu Apr 28, 2005 6:16 am
Posts: 20
Hi tmc, I had the same problem. Remove the lazy="true" and it will eagerly load.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 3:33 am 
Newbie

Joined: Wed May 04, 2005 9:01 am
Posts: 5
No - I already tried lazy="true" (see mapping above).


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 3:38 am 
Beginner
Beginner

Joined: Thu Apr 28, 2005 6:16 am
Posts: 20
Set lazy="false".


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 3:46 am 
Newbie

Joined: Wed May 04, 2005 9:01 am
Posts: 5
Sorry - didn't see you said "remove"....

However - I just tries this, and it still results in two SQL-statements. Even though it is set to lazy="true" it ought to be possible to load it eagerly by using "left join fetch".

But no matter how I declare the mapping, I can not seem to make it work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 4:31 am 
Beginner
Beginner

Joined: Thu Apr 28, 2005 6:16 am
Posts: 20
Sorry tmc, I don't know enough about how Hibernate works. Setting lazy=false resolved the problem though, no?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 4:34 am 
Newbie

Joined: Wed May 04, 2005 9:01 am
Posts: 5
No, it did not solve the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 3:17 pm 
Newbie

Joined: Thu Sep 11, 2003 11:49 am
Posts: 8
Location: Albuquerque NM
In your mapping try:

<one-to-one
.....
outer-join="true"
lazy="false"
>

If that works, please let me know :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 3:31 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
tmc wrote:
No, it did not solve the problem.


If the Main Class has a one-to-one relationship with Associated class, why does the Associated class have a many-to-one relationship back ? Shouldn't they both be one-to-one ?

Also, the class-level lazy=true might be effecting this.
Code:
<class
name="dk.mlon.appmoduler.medarbejder.impl.FritvalgDO"
schema="h7805"
table="fritvalg"
dynamic-insert="true"
dynamic-update="true"
lazy="true"
>


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 3:46 pm 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Just an FYI. In Hibernate version 2 Lazy defaults to "false". When you move to Hibernate version 3 Lazy defaults to "true". Remember this becasue what ever you do here to correct this problem, my may have to come back to it after upgrading.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 2:30 am 
Newbie

Joined: Wed May 04, 2005 9:01 am
Posts: 5
To clark98108:

<one-to-one
.....
outer-join="true"
lazy="false"
>

This does not solve the problem.

To pksiv:

Logically it should be a "one-to-one" association both ways. However - to do this - Hibernate demands that both ends have the same object-id. This is not the case for us. Therefore we map one end as a "many-to-one" (which is also described in the documentation).


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