Skip to main content

Are merge() and persist() syonymous?

2 replies [Last post]
Joined: 2005-01-15

It seems to me that the spec allows new Entity instances to be made managed and persistent either using EntityManager.persist() or EntityManager.merge(). Tried using either in Glassfish and it seems to work.

Could someone confirm that my understanding is correct?



Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-13

If you have a new entity X and call merge, then a copy X' of it becomes managed, according to section of the spec.

If you call persist, then X itself becomes managed.

That difference would not be observable in a simple test program.

However, if X is detached and you call persist, an exception is thrown. If you call merge, X is copied into a managed instance. You could easily write a test program to observe the difference.

Joined: 2005-01-15

It would nice to see the rationale for persist(). Seems to me that merge() is the more flexible interface.