4.4.4.2. Entity States

New

An instance which has been just created in memory: Car car = new Car().

New instance may be passed to EntityManager.persist() to be stored to the DB, in which case it switches into Managed state.

Managed

The instance loaded from DB, or a new one passed to EntityManager.persist(). Belongs to a EntityManager instance, i.e. is contained in its persistent context.

Any changes of the instance in Managed state will be saved to the DB when a transaction that the EntityManager belongs to is committed.

Detached

An instance loaded from the DB and detached from its persistent context (as result of transaction closing or serialization).

The changes applied to a Detached instance will be saved in DB only if this instance is switched back to the Managed state by being passed to EntityManager.merge().