Persistence Context in JPA

date
Aug 15, 2022
slug
persistence-context-in-jpa
status
Published
tags
Concept
JPA
Persistence Context
summary
type
Post
Persistence Context: Describes the relationship between all the Entity instances in our program and their representations in the underlying database.
Entities are managed by javax.persistence.EntityManager instance using Persistence Context.
Each EntityManager instance is associated with a Persistence Context.
Within the Persistence Context, the entity instances and their lifecycle are managed.
Persistence Context defines a scope under which particular entity instances are created, persisted, and removed.
Persistence Context is like a cache which contains a set of persistent entities, so once the transaction is finished, all persistent objects are detached from the EntityManager‘s Persistence Context and are no longer managed.
Summarily, a Persistence Context handles a set of entities which hold data to be persisted in some persistence store (e.g. a database). In particular, the context is aware of the different states an entity can have (e.g. managed, detached) in relation to both the context and the underlying persistence store.

References


© Foy Wan 2022 - 2025