-->
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.  [ 1 post ] 
Author Message
 Post subject: Move child from one parent to another
PostPosted: Tue Oct 10, 2006 6:09 pm 
Newbie

Joined: Thu Aug 10, 2006 12:25 am
Posts: 13
Hibernate version:3.1.3

Name and version of the database you are using:Posgtres

Hi

i have setup a parent child mapping which is working, I can save and update both which works well. I am using inverse='true' and a many-to-one mapping with cascade = all-delete-orphan

But my issue comes about when i want to move a child from one parent to another.

If I do

parent.getchildren.remove (child)
child.setparent(newparent)
newparent.getchildren.add(child)

hibernate throws an exception becuse it has queued and event to delete the child, from the first remove.

What i have to do is something like this
session.begintransaction
child.setparent(newparent)
newparent.getchildren.add(child)
session.gettrans.committrans()

session.refresh(parent)


I can't use remove cause this will cause a delete event to be queued.

but my problem if i have a 1000children this become very expensive.

Is there a way around this, or do I have to change my cascade to not include delete-oprhan ?


Alex


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.