JPA EntityManager, why merging () does not allow to manage the instance?

When I call merge () on an object, the object does not become manageable. Instead, a reference is returned to the managed instance of the same object. What is the logic behind this? Is there a way to change this behavior (and make control of the object) using some settings? I am using OpenJPA 2.2. Thanks.

+4
source share
1 answer

The fact is that merge () does not bind the object to the EntityManager context, it returns attached objects. So, if we have:

AEntity a2 = entityManager.merge(a1); 

a1 remains unmanageable, and a2 manages.

This, by the way, is a smart approach, since merging does not cause side effects, the state of the transferred object does not change.

+3
source

Source: https://habr.com/ru/post/1413075/


All Articles