18 June 2014

Entity Object Life Cycle


The life cycle of entity objects consists of four states: New, Managed, Removed and Detached.



  • When an entity object is initially created its state is New.
  • When an entity persisted to the database via an EntityManager’s persist method, the object becomes Managed.
  • Entity objects retrieved from the database by an EntityManager are also in the Managed state.
  •  A managed entity object can also be retrieved from the database and marked for deletion, by using the EntityManager’s remove method within an active transaction. The entity object changes its state from Managed to Removed.
  • Detached, represents entity objects that have been disconnected from the EntityManager. For instance, all the managed objects of an EntityManager become detached when the EntityManager is closed.

No comments:

Post a Comment

Like us on Facebook