Persistence Context Introduction#
What Is The Persistence Context#
Persistence context
: Thepersistence context
defines the set of active instances that the application is handling. Thepersistence context
can be created manually or through injection.- The
Persistence Context
is responsible for JPA entity management: When an application loads an Entity from the database, theentity
is in fact stored in thePersistence Context
, so theentity
becomes managed by thePersistence Context
. Any further change made over that sameentity
will be monitored by thePersistence Context
. - The
Persistence Context
will also flush changedentities
to the database when appropriate. When a transaction commits, the associatedPersistence Context
will also flush any eventual pending changes to the Database. - We can understand like the
persistence context
is the first-level cache where all theentities
are fetched from the database or saved to the database.
- The
Persistence Context Types#
Persistence Context
have two types: