-->
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: Initializing lazy associations
PostPosted: Mon Dec 08, 2003 12:17 pm 
Newbie

Joined: Mon Nov 24, 2003 2:38 pm
Posts: 11
Location: Santa Catarina, Brazil
Hello,

I have the associations below:

Code:
A <----> B (A->B = one-to-many, lazy=true), (B->A = many-to-one)
A <----> C (A->C = one-to-many, lazy=true), (C->A = many-to-one)
A <----> D (A->D = one-to-many, lazy=true), (D->A = many-to-one)
A <----> E (A->E = one-to-many, lazy=true), (E->A = many-to-one)
E <----> F (E->F = one-to-many, lazy=true), (F->E = many-to-one)

Because I'm working with a session disconnected from the view tier, I need to initialize the collections on DAO tier. To load the object "A" without load "F" I do this:

Code:
List result = session.find("from A");
Iterator ite = results.iterator();
while (ite.hasNext()) {
       A a = (A) ite.next();
       Hibernate.initialize(a.getBs());
       Hibernate.initialize(a.getCs());
       Hibernate.initialize(a.getDs());
       Hibernate.initialize(a.getEs());
}


Is there a better way to do this job?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
remove lazy=true ;-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 12:31 pm 
Newbie

Joined: Mon Nov 24, 2003 2:38 pm
Posts: 11
Location: Santa Catarina, Brazil
I


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 1:18 pm 
Newbie

Joined: Fri Dec 05, 2003 4:39 pm
Posts: 5
Location: Montr
In this case, would it make sense to have a separate configuration for "remoting" of objects?

Meaning, one configuration in which you do business code on the server, with lazy loads all over the place.

When it's time to go to the other tiers, you use a configuration that has everything eager...

Experts ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 2:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I personaly apply the 80%-20% rule. if BCD are needed 80% of your request then not lazy.
If BCD is needed 20% or less time then initialize is goods enough and more simple.

Quote:
In this case, would it make sense to have a separate configuration for "remoting" of objects?

Hum, lot's of pain and probably extra DB use since every request need to be executed twice... (1 for business mgt, and 1 for rendering). Whatever, duplicating mapping and managing 2 sessions and 2 sessionFactories is more or less a showstopper to me (2-PC Tx headache, ...).

_________________
Emmanuel


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.