-->
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.  [ 13 posts ] 
Author Message
 Post subject: Why is this property not lazy?
PostPosted: Thu Jun 09, 2005 11:08 am 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Hibernate version:
3.02

Mapping documents:
<class name="Member" table="dbo.MEMBER">
...
<many-to-one name="parent" column="PARENTID" property-ref="parentId" lazy="true" class="Member"/>
...
</class>

I've got this query that selects some Members. However, for every member that's returned, another select is issued to get the parent, which is also a member. I thought everything was supposed to be lazy by default? Why is Hibernate running all these unneeded selects? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 1:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
prefer fetch attribute, lazy need some instrumentation (for many-to-one and property)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 7:10 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
I've tried all possible combinations of "lazy" and "fetch", as well as leaving "lazy" out. Nothing's worked so far.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 9:22 am 
Newbie

Joined: Tue Jun 28, 2005 9:07 am
Posts: 3
I'm also needing badly this functionality - I think I could invest some of my coding time to do it, but I'm still pretty new to Hibernate (I've been debug-stepping over it several times, but still don't have a real grasp of the nuts and bolts). Could I give a hand with it? Does somebody have already an idea how this could be accomplished? Are there any resources available (besides the code itself, of course) where one could learn Hibernate implementation details?

José A. Romero L.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 9:56 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
pkulak wrote:
I've tried all possible combinations of "lazy" and "fetch", as well as leaving "lazy" out. Nothing's worked so far.


What does your entire mapping file look like ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 3:58 pm 
Beginner
Beginner

Joined: Sat Oct 09, 2004 2:35 pm
Posts: 43
Location: Tenerife
Same problem!
many-to-one relations with property-ref are all eager...
is this going to have any kind of solution in near future?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 6:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is no way to guaranty object unicity in the session if proeprty-ref associations are not loaded.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 8:05 am 
Beginner
Beginner

Joined: Sat Oct 09, 2004 2:35 pm
Posts: 43
Location: Tenerife
I agree this to be a default solution BUT it would be interesting, at least, to let the designer take a little control of this situation and leave a property to make it happen lazily.

My case:

I have a legacy table (e.g. TableOne) with 6 many-to-one property-ref relations.

What I only need is to lazily load these 6 tables every time I load a row from TableOne...

As some of these tables have, besides, some many-to-one property-ref relations, every time I try to load a row from TableOne I get 11 additional selects.

If I suppress property-ref, change my legacy database foreign keys to point to primary keys in secondary tables and change row data accordingly (uf!...), every read row does not get any may-to-one relation read automatically... instead, the secondary tables are read lazily as needed = everything is OK!.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No, think on it. Removing this object unicity restriction will break everything.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 5:51 pm 
Beginner
Beginner

Joined: Sat Oct 09, 2004 2:35 pm
Posts: 43
Location: Tenerife
I do not get the point of this situation...

Why if I suppress property-ref (use foreign key against primary key) I can use lazy loading and if I use property-ref everything must be eager?.

What I only suggest is to let the designer decide it using a property... If unicity breaks somewhere in any entity, there can be always the alternative of not using it... Now there is no alternative, only automatic solution...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 6:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you break unicity, you might lead to infinite loops in Hibernate.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 8:41 am 
Beginner
Beginner

Joined: Sat Oct 09, 2004 2:35 pm
Posts: 43
Location: Tenerife
I could say this is a designer problem but I am not going to say it...

I have changed a few tables relation to many-to-one primary key and the speed is considerable faster...

Have you noticed that people using legacy databases having this situation are consideralbly penalized because of this eager automatic selects?.

Anyway and finally I suppose that if you cannot make it possible is because the cons are superior to the pros...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 3:47 am 
Newbie

Joined: Tue Jul 31, 2007 5:16 am
Posts: 9
Please, is there any solution now?
I have the same problem but can't change the relations:

http://forum.hibernate.org/viewtopic.php?t=978077


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