-->
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: Deleting child object from parent
PostPosted: Wed Aug 23, 2006 8:25 am 
Newbie

Joined: Thu Jul 20, 2006 9:02 am
Posts: 2
Hibernate version:3.0

I have two classes, parent and child, where one parent can have a set of children. Now, I would like to delete a child.

Is there some way for me to delete this child, just using session.delete(child), without also having to remove the child object from the set of children stored in the parent object?

like:
public void delete(Child selectedChildToRemove) {
children.getParent().removeChild(selectedChildToRemove); //could I skip this line?
session.delete(selectedChildToRemove);
session.flush();
}

It seems to work, but i'm unsure wheter its the right way to go, if I configure the set like:
<class name="Parent" table="COUNTRY">
...
<set name="children" lazy="false" inverse="true" cascade="all-delete-orphan">
<key column="PARENT_ID" not-null="false" />
<one-to-many class="Child" />
</set>
</class>

All help is very apreciated.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 9:14 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
you can't skip that line as the deleted object will be resaved (because of the cascade setting) when you save the parent object. another appproach is to always save the parent object after you remove the child from the collection. in this case you don't need the session.delete call.

HTH,
radu


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.