-->
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: Easy way to save a cloned object as new?
PostPosted: Wed Nov 22, 2006 6:23 am 
Newbie

Joined: Tue May 23, 2006 12:46 pm
Posts: 17
Is there an easy to way to save a cloned object and its relationships as if they were transient? The two approaches we've tried have their problems.

The first is to have a method on our Entity interface which resets the ID to null and then calls the same method on any children. This is tideous to implement and error prone.

The second is to use reflection, writing a recursive method that looks for Entity relationships using reflection which also sets the IDs to null. This seems possible but we have to be careful about circular references.

So my question is...is there an easier way?

Also, do the proxies embedded in the Entities coming back from Hibernate contain state which could cause problems when saving clones back to the database?

Thanks.
Ashley


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 1:30 pm 
Newbie

Joined: Tue May 23, 2006 12:46 pm
Posts: 17
Just to update anyone who's interested...

We went with the reflective version in the end. We also had to make sure we replaced and PersistentCollections in the clone with normal Collections because they maintain state about their owning entity's primary key.


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.