is it possible to load entity (record), make changes to few fields, and persist it as a new entity?
My application uses Seam EntityHome to load entity, I would like to make copy of it change few fields and persist as new entity.
I guess I can do myentity=new MyEntity(); and set its each field to the one I want to clone from.
but I'm wondering if there is other neater way, like make clone, set ID to null, change few field as required and persist?
Seam 2.0.1GA + Hibernate.
If you clone a loaded hibernate entity you can't assume what you are dealing with exactly. It could be a hibernate proxy class... So for this reason I would stay away from this approach.
you probably want to create a new instance yourself and copy fields. Now if you don't want to hardcode the copying of fields method calls by method calls, you can probably use reflection to detect getters and call them or hibernate ClassMetaData if you want to focus only on properties that are mapped through hibernate.
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4165494#4165494