-->
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: Copy/Clone strategy for complex objects
PostPosted: Mon Dec 04, 2006 7:29 am 
Beginner
Beginner

Joined: Thu Aug 11, 2005 5:19 am
Posts: 29
Hi guys,

I have a real issue with cloning objects. I use session.merge(Object o) and it works fine, but after merge all the collections of the original object just get connected to the new object, so the target object just gets all the collections and the source object loses them. As I understand cascade=merge has to solve the problem, but not in my case.

Maybe someone has idea, how can I fix it?

Thank you very much in advance, and I'm sorry if it's somewhere in docs or forum, I honestly searched for solution for a couple of hours and here I am...


Hibernate version:
3.2.0


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 1:58 pm 
Newbie

Joined: Tue Sep 19, 2006 4:13 am
Posts: 18
Can you post your code where you are doing this stuff and more important also mention what do you expect the result to be.

I feel the problem is around you understanding of merge().


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 2:15 pm 
Beginner
Beginner

Joined: Thu Aug 11, 2005 5:19 am
Posts: 29
Hi *monu,

what I basically do is:

1) Make a clone of the MyObject o (with DeepCopy)
2) set a o.ID to Null
2) Session.merge(o).

MyObject has couple of collections, particularly maps with composite ID MyObject.compositeIdDetail(ID:[product_id, locale] , name)

and particularly bags with real ID, like:

MyObject.realIdDetail(ID, product_id, name, locale, text)

I have no problems with these composite ID collections, but the details with a real ID are just getting rewritten with an ID of the new Object.

What I want is a real clone, incl. all collections.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 5:26 am 
Beginner
Beginner

Joined: Thu Aug 11, 2005 5:19 am
Posts: 29
Hi guys, problem solved.

I just had to iterate all the collections with a real ID (not a composite one) and set their IDs to null before merging.


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.