tenwit wrote:
Supun wrote:
I load an Entity from a Session at the start of a conversation. I serialize the object to an external cache (ie, memcache d) after the session the is closed. A long while later that same object is looked up in the cache and is to be edited by the application. If we are to attach it to the Session, should we use update() or persist()?
Neither. Use replicate or merge.
Just a question on this: the latest (3.2.1) hibernate documentation says, in section 10.6:
Quote:
Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session. In other words, update() is usually the first method you would call in a fresh session, ensuring that reattachment of your detached instances is the first operation that is executed.
So the suggestion is to use update() normally, not merge().
Using merge() might bear the risk that you have accidentally loaded the original instance from the database, and now you have confustion since you have your detached (possibly modified) instance and a fresh attached instance. This would most probably be a programming error, and when using merge() such an error would go undetected.
Why do you think one should use merge() instead of update()?