Hibernate Updating an existing entity with a new object
Posted
by DD
on Stack Overflow
See other posts from Stack Overflow
or by DD
Published on 2010-03-26T09:13:16Z
Indexed on
2010/03/26
9:33 UTC
Read the original article
Hit count: 241
hibernate
Hi, Assume I have an entity Foo in the DB.
I am parsing some files and creating new Foo objects and would like to check if the parsed Foo object exists in the DB (using a unique attribute). If it exists already update it otherwise save as a new object.
What is the best approach?
Could I simply set the id and version in the new Foo object?
Or would I be better off loading the Foo object from the DB and copying over the properties from the parsed file?
Thanks.
© Stack Overflow or respective owner