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
|