Entities are managed by the instances of javax.entity.EntityManager
in the Java application. Entities have a lifecycle of four states: new, managed, detached, and removed.
An entity bean is in the new state when it is instantiated with the Java new operator, or serialized from the object stream. In the new state, entity bean is not associated with any EntityManager
instance whatsoever. An alternative way to specify this is to say that the entity bean has no persistence context, and therefore, no persistence identity.
An entity bean is in the managed state when it is associated with an EntityManager
instance and that instance is still valid in terms of the JVM. A managed entity bean has a definite persistence context and identity.
An entity bean is in the detached state when it is no longer associated with an EntityManager
. A detached entity can be found if the entity bean is serialized into an object stream so that it is transferred across the network from one JVM to another. A detached entity can be found if its associated EntityManager
goes out of scope.
A detached entity bean can be reattached with EntityManager
during a merge operation, as we will see later in the discussion around management.
18.116.80.45