-->
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: Best way to make entities cloneable?
PostPosted: Mon Feb 21, 2011 8:22 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I need to create clones of database entities (with some specific fields changed and new IDs generated).
The use case is that the database table contains "template rows", and whenever a new row is required, it starts life as a copy of a template row. The copying operation should not have to enumerate all fields that need to be copied, since that would be fragile under database schema changes.

I see three approaches: Object#clone, BeanUtils.cloneBean, and serialize/unserialize.

Any advice on how to best proceed? I can see various advantage and disadvantages for any way, but I don't know which are even relevant.
Things to consider:
* Efficiency of the flat clone itself
* How to initialize Set members (they should be empty for the clone)
* Shouldn't trigger initialization for lazily-initialized members


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.