-->
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: set of childred doesn't get modified when child is deleted
PostPosted: Wed Dec 14, 2005 8:21 am 
Beginner
Beginner

Joined: Thu Sep 22, 2005 7:22 am
Posts: 21
a class has a method getChildren() now I just want to delete one child using session.delete(aChild). if I invoke getChildren() it still contains the child I deleted.
Is it possible to make the deletion of the child update the set that is returned from getChildren() or is it just not how it is supposed to be done?

I come to think about 2 different sollutions;
1. explicitly remove the child from the getChildren() Set. problem is that there might be several sets that need to be explicitly updated, and also, the set might not be available where the deletion occurs.

2. I dont delete the child, but instead removes it from the Set and update. That just feels like a stupid thing to do..

Need some pointing in the right direction here!
Thanks!

_________________
/ted


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 2:08 pm 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
You can define a mapping, so that the child objects are deleted when they are removed from the parent's collection.

The mapping is as follows (within the parent class mapping):

Code:
...
<set name="children"
     cascade="all,delete-orphan"
     inverse="true">
    <key column="CU_PARENT"/>
    <one-to-many class="Child"/>
</set>
...


This assumes, that the children are associated by a foreign key to the parent in the child's table.

I believe, the key points are the cascade and the inverse part.

Does that help?

All the best,

René


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.