Hibernate Updating an existing entity with a new object
- by DD
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.