Skip to content

Hibernate update vs merge

May 7, 2012

Update and Merge both work on detached instances,
ie instances which have a corresponding entry in the DB but which are
currently not attached to (or managed by) a Session. The difference between
them are what happens to the instance which is passed to the function.
update tries to reattach the instance, that means that there may be no
other instance of the persistent entity attached to the Session right now otherwise
a exception is thrown. merge, however, just copies all values to a persistent instance in the Session
(which will be loaded if it is not currently loaded).
The input object is not changed. So merge is more general than update, but may use more resources

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: