ClassBook-Lesson02-The Persistence Life Cycle
ClassBook-Lesson02-The Persistence Life Cycle
Instructor Notes:
Page 02-1
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Page 02-2
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Similarly, objects created in your application, when passed to ORM, get stored
in database table. How it happens? What work goes in background? How
your object persisted in database?
This lesson tries to answer abstract working of ORM and we will discuss in
details about the object’s persistence life cycle.
Page 02-3
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Entity Manager:
The EntityManager is the primary interface used by application developers to
interact with the JPA runtime.
Persistence Context:
Persistence context defines a scope under which particular entity instances
are created, persisted, and removed.
The slide diagram shows a sample JPA runtime. JPA uses EntityManager
instance to manage objects which required to be persisted. Such objects are
called Entities. Entities managed by EntityManager travels through different
life cycle phases. This lesson primarily focuses on entities persistence life
cycle.
Page 02-4
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
The slide diagram shows different states of entity. When entity is in managed
state, the data of entity is persisted in database.
Page 02-5
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
New State :When an entity object is initially created its state is New. In this
state the object is not yet associated with an Entity Manager and has no
representation in the database.
Page 02-6
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Entity objects retrieved from the database by an EntityManager are also in the
Managed state.
Page 02-7
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Detached State : 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.
Page 02-8
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Page 02-9
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Removed 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, and is physically deleted from the database during
commit.
Page 02-10
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Page 02-11
JPA with Hibernate 3.0 The Persistence Life Cycle
Instructor Notes:
Answers:
1. True
2. Managed
Page 02-12