-->
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: Update old parent entity when child moves to new parent?
PostPosted: Mon Dec 26, 2005 12:58 am 
Newbie

Joined: Mon Dec 26, 2005 12:01 am
Posts: 2
Hi All,

I have a situation where i have a child object attached to a parent object (via a many to one relationship). The child object can be uniquely identified with a business key. I have situations where the child object can 'move' to a different parent. Currently, I'm doing this by executing a delete statement that deletes the child before i attach it to the new parent, and then saving the parent via the session.

I was wondering if there's a better way of doing this?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 1:18 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Use Association. Learn more from the below link,

http://www.hibernate.org/hib_docs/v3/re ... sociations

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 4:15 am 
Newbie

Joined: Mon Dec 26, 2005 12:01 am
Posts: 2
Ramnath,
As I've mentioned in my post, I'm already using a many-to-one association for the parent-child relationship. Do you have a specific recommendation that would help address my question?
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 10:16 am 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
You should be able to just update the relationship(s) and have hibernate move it without having to delete and re-create.

Are you using bidirectional many-to-one associations? In that case one side is the master relationship and the other is just a backpointer that does not "drive" the association. The backpointer side should be marked "inverse=true" in the mappings.

In this case you need to be sure to update the right side of the bidirectional association so that the data is saved. Best practice is to do both updates with a pattern where each set updates the other link also via an addXxx() method that sets both relationships.

see: http://www.hibernate.org/116.html#A10


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.