-->
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.  [ 4 posts ] 
Author Message
 Post subject: delete child from one-to-many: best practice
PostPosted: Mon Dec 14, 2009 5:48 am 
Newbie

Joined: Mon Dec 14, 2009 5:38 am
Posts: 13
hello,
I'm new to Hibernate, and I'm facing one problem here....
I have one-to-many mapping, and I want to delete from child table.
this are the steps:
1. I load the parent data into forms (collection of textfields), and the child data into an arraylist
2. I delete one of the arraylist item
3. I save the parent data and the child data

now, the steps of saving the data is that I put all the arraylist items, into a java.util.List,
and then save it.

the child item is deleted (I can't see it when I load the parent), but the problem is, it's still there
in the database, but it's parent_id value is null.

does anyone have a better practice about this, or suggestion?
thanks


Top
 Profile  
 
 Post subject: Re: delete child from one-to-many: best practice
PostPosted: Mon Dec 14, 2009 6:50 am 
Beginner
Beginner

Joined: Mon Dec 14, 2009 12:26 am
Posts: 23
The key term you are looking for is probably "orphan removal".

http://www.google.com.au/search?q=hibernate+orphan+removal


Top
 Profile  
 
 Post subject: Re: delete child from one-to-many: best practice
PostPosted: Mon Dec 14, 2009 11:11 am 
Newbie

Joined: Mon Dec 14, 2009 5:38 am
Posts: 13
hi ringerc,
if I'm not mistaken, usually the term orphan-delete is to delete "orphaned" children when we delete the parent.
but for my problem, I want to delete a child/children when the parent is still there.
I really don't know the best practice of how to do that. I only know to fetch the data into an arraylist,
delete the item I don't want from that arraylist, and then I save that arraylist.


Top
 Profile  
 
 Post subject: Re: delete child from one-to-many: best practice
PostPosted: Wed Dec 16, 2009 4:23 am 
Newbie

Joined: Mon Dec 14, 2009 5:38 am
Posts: 13
Hi ringerc,
I think I've mistakenly understood the "flow",
I should delete the children from the parent class, instead of deleting the children from the arraylist,
because it's only the view, and not the data...

thank you for pointing me to the articles...

Faizal


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