Detach Behavior

The detach behavior has changed in several ways:

  • In the 1.x.x release, managed entities were flushed to the database as part of the detach operation. This is no longer done in 2.0.

  • In the 1.x.x release, entities were copied and returned. In 2.0, for those methods that have return values, the original entities are returned.

  • In the 1.x.x release, managed entities still exist in the persistent context. In 2.0, they are removed.

  • In the 1.x.x release, the detach operation is recursively cascaded to all referenced entities. In 2.0, the detach operation is only cascaded to those entities for which Cascade=detach has been specified.

Applications that use a 1.0 persistence.xml will automatically maintain OpenJPA 1.x.x behavior. It is possible for a version 2.0 application to revert back to the 1.x.x behavior for some of these items by setting the openjpa.Compatibility property as follows:

In addition, a new method has been provided on the OpenJPAEntityManager interface to return a copy of the entity:

    public <T> T detachCopy(T pc):