Quantcast
Channel: JPA EntityManager: Why use persist() over merge()? - Stack Overflow
Viewing all articles
Browse latest Browse all 17

Answer by Krystian for JPA EntityManager: Why use persist() over merge()?

$
0
0

persist(entity) should be used with totally new entities, to add them to DB (if entity already exists in DB there will be EntityExistsException throw).

merge(entity) should be used, to put entity back to persistence context if the entity was detached and was changed.

Probably persist is generating INSERT sql statement and merge UPDATE sql statement (but i'm not sure).


Viewing all articles
Browse latest Browse all 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>