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.
source share