3.13.1.1. Detach Behavior
|
|
In version 2.0, the detach behavior has changed from the previous version. See the migration section Detach Behavior for details. |
In JPA, objects detach automatically when they are serialized or when a persistence context ends. The specification also allows objects to be explicitly detached using the following jakarta.persistence.EntityManager method:
public void detach(Object)
OpenJPAEntityManager, however, provides additional detach methods.
public <T> T detachCopy(T pc):
public Object[] detachAll(Object... pcs):
public Collection detachAll(Collection pcs):
The behavior of the detach operation is as follows:
-
The detached objects are removed from the persistent context.
-
The objects are not flushed to the database.
-
If Cascade=detach is specified for a referenced entity, the detach operation is cascaded. Otherwise, it is not.
-
For the detachCopy method only, the entity is copied for the return value.