-->
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.  [ 5 posts ] 
Author Message
 Post subject: ONE-TO-ONE ASSOCIATIONS LAZY LOADING PROBLEMS
PostPosted: Mon Oct 23, 2006 9:35 am 
Newbie

Joined: Mon Oct 23, 2006 9:03 am
Posts: 5
Location: La Spezia, Italy
I have a problem when I'm loading an object (A) having two one-to-one relationship with another kind of object(B):

the associations are bidirectional and lazy loading seems not function. In a few words, when I get the object A, hibernate retrive immediately from database two objects B.

Hibernate: select this_.HDHAND as HDHAND102_0_, this_.PRPARCOD as PRPARCOD102_0_, this_.HDPARKBAY as HDPARKBAY102_0_, this_.HDPARKRO as HDPARKRO102_0_, this_.HDPARKTIER as HDPARKTIER102_0_, this_.TIYBA as TIYBA102_0_, this_.HDCOMCLS as HDCOMCLS102_0_, this_.HDPREFIX as HDPREFIX102_0_, this_.HDSERIAL as HDSERIAL102_0_, this_.HDCHKDIG as HDCHKDIG102_0_, this_.HDPLANIN as HDPLANIN102_0_ from YDATTST.HAND00F this_ fetch first 1 rows only |#]

Hibernate: select liftingin0_.LILIFT as LILIFT103_0_, liftingin0_.HDHAND as HDHAND103_0_, liftingin0_.LIREFVIS as LIREFVIS103_0_ from YDATTST.LIFT00F liftingin0_ where liftingin0_.HDHAND=? and liftingin0_.LILISEQUEN='1000'|#]

Hibernate: select liftingout0_.LILIFT as LILIFT103_0_, liftingout0_.HDHAND as HDHAND103_0_, liftingout0_.LIREFVIS as LIREFVIS103_0_ from YDATTST.LIFT00F liftingout0_ where liftingout0_.HDHAND=? and liftingout0_.LILISEQUEN='2000'|#]


These are the mappings of the two class:

A=>Handling
B=>Lifting

A)<hibernate-mapping>
<class
name="app.tis.lib.Handling"
table="YDATTST.HAND00F"
polymorphism="implicit"
lazy="true"
dynamic-update="true"
optimistic-lock="dirty"
>
<id
name="id"
column="HDHAND"
type="long"
>
</id>
<generator class="assigned"></generator>
...
<one-to-one name="liIn" lazy="proxy" class="app.tis.lib.LiftingIn" property-ref="hd" constrained="true"/>

<one-to-one name="liOut" lazy="proxy" class="app.tis.lib.LiftingOut" property-ref="hd" constrained="true"/>

</class>

</hibernate-mapping>

B)<hibernate-mapping>

<class name="app.tis.lib.Lifting" table="YDATTST.LIFT00F" lazy="true">
<composite-id name="id" class="app.tis.compositepk.LiftingId">
<key-property name="liftNum" column="LILIFT"></key-property>
<key-property name="hdHand" column="HDHAND"></key-property>
</composite-id>

<discriminator column="LILISEQUEN" type="string" />

<subclass name="app.tis.lib.LiftingIn" discriminator-value="1000" lazy="true">
<many-to-one
lazy="proxy"
insert="false"
update="false"
name="hd"
class="app.tis.lib.Handling"
unique="true"
column="HDHAND">
</many-to-one>
</subclass>

<subclass name="app.tis.lib.LiftingOut" discriminator-value="2000" lazy="true">
<many-to-one
lazy="proxy"
insert="false"
update="false"
name="hd"
class="app.tis.lib.Handling"
unique="true"
column="HDHAND"
>
</many-to-one>
</subclass>

</class>

</hibernate-mapping>


Someone can explain me why lazy loading goes away????I try setting lazy=true/proxy everywhere is possible
Thank you in advance

_________________
A T


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 9:42 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
I think this WIKI entry should help you:

http://www.hibernate.org/162.html

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 9:50 am 
Newbie

Joined: Mon Oct 23, 2006 9:03 am
Posts: 5
Location: La Spezia, Italy
MikePloed wrote:
I think this WIKI entry should help you:

http://www.hibernate.org/162.html


I have already read this article and I follow it; it says:

if your B->C mapping is mandatory (constrainted=true), Hibernate will use proxy for C resulting in lazy initialization

If you see my mappings there is a constrainted=true on the two one-to-one relationship; but lazy loading doesn't work

HELP!!!

_________________
A T


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 9:56 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Yes, but you did not enable proxy on the class / subclass, have a look at the first comment on the wiki page:

Quote:
The one-to-one reference is only loaded lazily if the object used as the
class has a proxy or is lazy (proxy is the object itself). I didn't read
it the first time, so it didn't work out as it should.

Just use

<class name="C" lazy="true">

or

<class name="C" proxy="CProxy">

and it will do.


_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 10:03 am 
Newbie

Joined: Mon Oct 23, 2006 9:03 am
Posts: 5
Location: La Spezia, Italy
I enable proxy on the class/subclass

For Lifting:
<class name="app.tis.lib.Lifting" table="YDATTST.LIFT00F" lazy="true">
<subclass name="app.tis.lib.LiftingIn" discriminator-value="1000" lazy="true">
<subclass name="app.tis.lib.LiftingOut" discriminator-value="2000" lazy="true">

For Handling
<class name="app.tis.lib.Handling" table="YDATTST.HAND00F" polymorphism="implicit" lazy="true" dynamic-update="true" optimistic-lock="dirty">

Have you seen?

_________________
A T


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