Derek Mahar
Derek Mahar

Reputation: 28386

What are the differences between Hibernate Session methods saveOrUpdate() and merge()?

What are the differences between Hibernate Session methods saveOrUpdate(Object) and merge(Object)? It seems that both methods generate an SQL INSERT statement when the given object does not exist in the corresponding table and an UPDATE when it does exist.

Upvotes: 7

Views: 3643

Answers (3)

Derek Mahar
Derek Mahar

Reputation: 28386

SaveOrUpdate versus Merge in Hibernate explains the differences between saveOrUpdate() and merge().

Upvotes: 1

Scott
Scott

Reputation: 338

If I remember correctly, merge is for un-associated instances, that aren't currently managed. It will do a lookup based on id and merge the two.

Upvotes: 1

jpkroehling
jpkroehling

Reputation: 14061

Even though this is for NHibernate, it also applies to Hibernate:

NHibernate - Difference between session.Merge and session.SaveOrUpdate?

Upvotes: 1

Related Questions