-->
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.  [ 8 posts ] 
Author Message
 Post subject: Deep cloning an object containing a Collection
PostPosted: Wed Nov 17, 2004 6:02 pm 
Newbie

Joined: Mon Oct 04, 2004 4:25 pm
Posts: 7
I've searched the forum for topics concerning cloning a persisted object containing a collection with the intent of persisting the new object. I've seen replies from the Hibernate team about using the Metadata API for this, but I've yet to see a good example. With the number of folks trying to do this, it would seem that someone has come up with a good (generic) solution.

The example in 9.10 of the Hibernate reference document seems to offer a hint. It collects the properties that are not entities or collections, but does nothing with them. (As a side note, the documentation is in error--there is no isCollectionType() method on the Type class--I believe it's supposed to be isPersistentCollectionType()). I assume I could use

catMeta.setPropertyValue(newFritz, propertyNames[i], propertyValues[i]);

to copy these properties, but that doesn't really accomplish the task. The problem is that a persisted Collection in the object needs to cloned in such a manner that when the containing object is saved, a copy of the collection is added as well. If I simply deepClone my object, I get

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

on the Collection when the cloned object is saved. If I try to reuse the collection in the newly cloned object, a different exception is thrown.

So, what does the code (metadata API?) look like to solve this problem in a generic way?

Thanks.

--
Phil


Top
 Profile  
 
 Post subject: Did you get any resolution to this
PostPosted: Mon Dec 06, 2004 2:45 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
Did you get any resolution to this


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 2:50 pm 
Newbie

Joined: Mon Oct 04, 2004 4:25 pm
Posts: 7
I ended up digging through the MetaData API and coding my own solution. I would post it, but I am not confident that it's a generic solution (although it does seem to satisfy my needs for the moment).

--
Phil


Top
 Profile  
 
 Post subject: Can you send an example implementation to me?
PostPosted: Mon Dec 06, 2004 3:04 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
Can you send an example implementation to me?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 3:09 pm 
Newbie

Joined: Mon Oct 04, 2004 4:25 pm
Posts: 7
I don't see your e-mail address in your profile.

--
Phil


Top
 Profile  
 
 Post subject: my email address
PostPosted: Tue Dec 07, 2004 2:23 pm 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
my email address is garpinc (.at.) yahoo.com


Top
 Profile  
 
 Post subject: Re: Deep cloning an object containing a Collection
PostPosted: Fri Dec 10, 2004 2:04 pm 
Newbie

Joined: Thu Nov 04, 2004 12:29 pm
Posts: 1
Hi,

I have a similar problem. Would you mind sharing your solution with me? You can email me at sgalgali@medplus.com.

Thanks,
-SG


Top
 Profile  
 
 Post subject: example implementation
PostPosted: Tue Sep 27, 2005 9:06 am 
Newbie

Joined: Tue Sep 27, 2005 9:02 am
Posts: 1
Did any one manage to get an example implementation of this? I'm trying to implement the same and it would be very helpful if somebody could send this at visves77 at yahoo dot com.

Thanks


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