-->
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: Hibernate --> Child deleting problems
PostPosted: Fri May 12, 2006 7:12 am 
Newbie

Joined: Fri May 12, 2006 7:07 am
Posts: 2
Hi,

I have following script in parent hbm file for child as:

<set name="child" lazy="false" inverse="true" cascade="all-delete-orphan">
<key column="ChildId"/>
<one-to-many column="ParentId" class="Child"/>
</set>

the problem is when i update the child with parent or insert more childrens so there is no problem. but when i update the parent with child. if child insertable or updatable so it perform that tasks. and if some child is deleted in the sets so it does't deleted the childs.

for example

i insert the record Parent with child

Parent p = new Parent("1001");
p.addChild(new Child("201"));
p.addChild(new Child("202"));
p.addChild(new Child("203"));

--- open session ----
session.save(p);
--- close session ----


so it save parent with three childs.

and after this task when i update this record as per following.

Parent p = new Parent("1001");
p.addChild(new Child("201"));
p.addChild(new Child("203"));
p.addChild(new Child("204"));

--- open session ----
session.update(p);
--- close session ----


so it add more one child according with parent. but not delete the child have id"202".

my problem is this. pls give me proper answer or example very very thanks in advance for this solutions.

Thanks & Regards
Muhammad Shoaib Ashrafi


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 11:55 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
If i get this right, what you want is that you want to remove the child with id 202. Do the following:

Code:
p.removeChild(new Child("201"));


which will remove the child from the collection. The save/update the parent.


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.