• An entity is a persistence domain object. Entity represents a table in a relational database, and each entity instance corresponds to a row in that table.
  • JPA uses Annotations or XML to map entities to a Relational database.
  • The persistent state of an entity fields or properties (setter and getter methods) use object/relational mapping annotations to map the entities and entity relationships to the relational data in the underlying data store.


  • EntityManager is an interface to perform main actual database interactions.
    1. Creates persistence instance.
    2. Removes persistence instance.
    3. Finds entities by entity’s primary key.
    4. Allows queries to be run on entities.
  • Persistence Context : A persistence context handles a set of entities which hold data to be persisted in some persistence store (e.g. database).
  • Each EntityManager instance is associated with a Persistence Context.

Persistence Unit:

  • A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application.
  • This set of entity classes represents the data contained within a single data store.
  • Persistence units are defined by the persistence.xml configuration file.
  • JPA uses the persistence.xml file to create the connection and setup the required environment. Provides information which is necessary for making database connections.
  • Example persistence.xml configuration:

Persistence Class:

  • Persistence (javax.persistence.Persistence) class contains java static methods to get EntityManagerFactory instances.

EntityManagerFactory :

  • EntityManagerFactory (javax.persistence.EntityManagerFactory) class is a factory for EntityManagers.
  • During the application startup time EntityManagerFactory is created with the help of Persistence-Unit.
  • Typically, EntityManagerFactory is created once (One EntityManagerfactory object per Database) and kept alive for later use.

EntityTransaction :

  • A transaction is a set of operations that either fail or succeed as a unit.
  • A database transaction consists of a set of SQL operations that are committed or rolled back as a single unit
  • Any kind of modifications initiated via EntityManager object are placed within a transaction. An EntityManager object helps creating an EntityTransaction

JPA Architecture :

JPA ARchitecture