Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
18. Jul 2008, 19:43 CET | Link

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.

2 Replies:
18. Jul 2008, 20:29 CET | Link

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.

19. Jul 2008, 16:32 CET | Link
Hi thanks for the reply. The hibernate ClassMetaData appears more appropriate for my case, however Im getting exception when it tries to access getter methods for property defiend in entity superclass. I have posted detailed information on hibernate forum.

http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4165494#4165494