JPA Container Injection Annotations

Jakarta Persistence (JPA) provides standard annotations to manage dependencies on container-managed persistence resources in both Jakarta EE and Spring Framework environments. They enable the container to inject EntityManager or EntityManagerFactory proxies directly into application components such as services and DAOs.

EntityManager injection

Inject an EntityManager and configure its scope using the following annotations:

Expresses a dependency on a container-managed EntityManager, injecting a shared, thread-safe proxy associated with the current transaction.

Specifies the lifetime scope of the persistence context: TRANSACTION (default) or EXTENDED (spanning multiple transactions).

A container annotation for declaring multiple @PersistenceContext definitions on a single class.

EntityManagerFactory injection

Inject an EntityManagerFactory using these annotations:

Expresses a dependency on an EntityManagerFactory, useful for creating EntityManagers manually or accessing factory metadata.

A container annotation for declaring multiple @PersistenceUnit definitions on a single class.

Configuration Properties

Define vendor-specific properties or configuration overrides:

Used within @PersistenceContext or @PersistenceUnit to specify configuration properties for the injected resource.