-->
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.  [ 2 posts ] 
Author Message
 Post subject: lazy initialization in hibernate
PostPosted: Thu Jan 18, 2007 11:29 am 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
Hi, just have a question related to lazy load.

I have a class, which has 1 set for relations among objects.

when I load the class, I don't want to load the relation set.

1. when I do the update, do I have to load relation set. (I don't want to update relation set as well).

e.g.

loadMyClass(class, relationSetFlag = false);
updateMyClass(class)

(as right now I get lazy load error)

So I guess this might work

loadMyClass(class, false);
class.setRelationSet(null);
updateMyClass(class)

2. how about delete?

If I don't load the relation set, when I delete the class, will the relation to be deleted? I want to them to be deleted.

Thanks much.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 12:15 am 
Newbie

Joined: Thu Jan 18, 2007 12:55 am
Posts: 10
lazy loading is set to true for any assosciation with hibernate, so if you load the parent class, children association don't get loaded by default.

I am not sure why you have load the relation,(assosciated object) while you do an update, if you are updating the parent object, the parent child relationship is generally through a foreign key is present in the child table.
Unless you wan't that foreing key to be updated on the child table

every collection has a attribute called cascade
if you put attribute cascade="all-delete-orphan" on the collection mapping , when you delete the parent object it will automatially delete the underlying assosciated relationship.


I hope this helps.


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