jakarta.persistence.EntityManager
proxies that follow the JPA spec's semantics for "extended" EntityManagers.
Supports several variants of "extended" EntityManagers:
in particular, an "application-managed extended EntityManager", as defined
by jakarta.,
as well as a "container-managed extended EntityManager", as defined by
jakarta..
The original difference between "application-managed" and "container-managed"
was the need for explicit joining of an externally managed transaction through
the EntityManager#joinTransaction() method in the "application" case
versus the automatic joining on each user-level EntityManager operation in the
"container" case. As of JPA 2.1, both join modes are available with both kinds of
EntityManagers, so the difference between "application-" and "container-managed"
is now primarily in the join mode default and in the restricted lifecycle of a
container-managed EntityManager (i.e. tied to the object that it is injected into).
jakarta.persistence.EntityManagerFactory#createEntityManager() , jakarta.persistence.PersistenceContextType#EXTENDED , jakarta.persistence.EntityManager#joinTransaction() , SharedEntityManagerCreator
| Modifier and Type | Class and Description |
|---|---|
| private static class | ExtendedEntityManagerCreator.
InvocationHandler for extended EntityManagers as defined in the JPA spec. |
| private static class | ExtendedEntityManagerCreator.
TransactionSynchronization enlisting an extended EntityManager with a current Spring transaction. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static EntityManager | Returns: an application-managed EntityManager that can join transactions but does not participate in them automaticallythe raw EntityManager to decorate rawEntityManager, EntityManagerFactoryInfo the EntityManagerFactoryInfo to obtain the JpaDialect
and PersistenceUnitInfo from emfInfo)Create an application-managed extended EntityManager proxy. |
| public static EntityManager | Returns: an application-managed EntityManager that can join transactions but does not participate in them automaticallythe raw EntityManager to decorate rawEntityManager, EntityManagerFactoryInfo the EntityManagerFactoryInfo to obtain the JpaDialect
and PersistenceUnitInfo from emfInfo, boolean whether to automatically join ongoing
transactions (according to the JPA 2.1 SynchronizationType rules) synchronizedWithTransaction)Create an application-managed extended EntityManager proxy. |
| public static EntityManager | Returns: a container-managed EntityManager that will automatically participate in any managed transactionthe raw EntityManager to decorate rawEntityManager, EntityManagerFactoryInfo the EntityManagerFactoryInfo to obtain the JpaDialect
and PersistenceUnitInfo from emfInfo)Create a container-managed extended EntityManager proxy. |
| public static EntityManager | Returns: a container-managed EntityManager that will automatically participate in any managed transactionthe EntityManagerFactory to create the EntityManager with.
If this implements the EntityManagerFactoryInfo interface, the corresponding
JpaDialect and PersistenceUnitInfo will be detected accordingly. emf)Create a container-managed extended EntityManager proxy. |
| public static EntityManager | Returns: a container-managed EntityManager that will automatically participate in any managed transactionthe EntityManagerFactory to create the EntityManager with.
If this implements the EntityManagerFactoryInfo interface, the corresponding
JpaDialect and PersistenceUnitInfo will be detected accordingly. emf, Map<?, ?> the properties to be passed into the properties)createEntityManager
call (may be null)Create a container-managed extended EntityManager proxy. |
| public static EntityManager | Returns: a container-managed EntityManager that expects container-driven lifecycle management but may opt out of automatic transaction synchronizationthe EntityManagerFactory to create the EntityManager with.
If this implements the EntityManagerFactoryInfo interface, the corresponding
JpaDialect and PersistenceUnitInfo will be detected accordingly. emf, Map<?, ?> the properties to be passed into the properties, boolean createEntityManager
call (may be null)whether to automatically join ongoing
transactions (according to the JPA 2.1 SynchronizationType rules) synchronizedWithTransaction)Create a container-managed extended EntityManager proxy. |
| private static EntityManager | Returns: the EntityManager proxyraw EntityManager rawEntityManager, EntityManagerFactoryInfo the EntityManagerFactoryInfo to obtain the JpaDialect
and PersistenceUnitInfo from emfInfo, boolean whether to follow container-managed EntityManager
or application-managed EntityManager semantics containerManaged, boolean whether to automatically join ongoing
transactions (according to the JPA 2.1 SynchronizationType rules) synchronizedWithTransaction)Actually create the EntityManager proxy. |
| private static EntityManager | Returns: the EntityManager proxyraw EntityManager rawEm, Class<? extends EntityManager> the (potentially vendor-specific) EntityManager
interface to proxy, or emIfc, ClassLoader null for default detection of all interfacesthe ClassLoader to use for proxy creation (maybe cl, PersistenceExceptionTranslator null)the PersistenceException translator to use exceptionTranslator, Boolean whether to create a JTA-aware EntityManager
(or jta, boolean null if not known in advance)whether to follow container-managed EntityManager
or application-managed EntityManager semantics containerManaged, boolean whether to automatically join ongoing
transactions (according to the JPA 2.1 SynchronizationType rules) synchronizedWithTransaction)Actually create the EntityManager proxy. |
| cachedEntityManagerInterfaces | back to summary |
|---|---|
| private static final Map<Class<?>, Class<?>[]> cachedEntityManagerInterfaces | |
| ExtendedEntityManagerCreator | back to summary |
|---|---|
| public ExtendedEntityManagerCreator() | |
| createApplicationManagedEntityManager | back to summary |
|---|---|
| public static EntityManager createApplicationManagedEntityManager(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) Create an application-managed extended EntityManager proxy.
| |
| createApplicationManagedEntityManager | back to summary |
|---|---|
| public static EntityManager createApplicationManagedEntityManager(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean synchronizedWithTransaction) Create an application-managed extended EntityManager proxy.
| |
| createContainerManagedEntityManager | back to summary |
|---|---|
| public static EntityManager createContainerManagedEntityManager(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo) Create a container-managed extended EntityManager proxy.
| |
| createContainerManagedEntityManager | back to summary |
|---|---|
| public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf) Create a container-managed extended EntityManager proxy.
| |
| createContainerManagedEntityManager | back to summary |
|---|---|
| public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf, Map<?, ?> properties) Create a container-managed extended EntityManager proxy.
| |
| createContainerManagedEntityManager | back to summary |
|---|---|
| public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf, Map<?, ?> properties, boolean synchronizedWithTransaction) Create a container-managed extended EntityManager proxy.
| |
| createProxy | back to summary |
|---|---|
| private static EntityManager createProxy(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean containerManaged, boolean synchronizedWithTransaction) Actually create the EntityManager proxy.
| |
| createProxy | back to summary |
|---|---|
| private static EntityManager createProxy(EntityManager rawEm, Class<? extends EntityManager> emIfc, ClassLoader cl, PersistenceExceptionTranslator exceptionTranslator, Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) Actually create the EntityManager proxy.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private final PersistenceExceptionTranslator | |
| private final boolean | |
| private static final Log | |
| private final boolean | |
| private final EntityManager |
| Access | Constructor and Description |
|---|---|
| private | ExtendedEntityManagerInvocationHandler(EntityManager target, PersistenceExceptionTranslator exceptionTranslator, Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction)
|
| Modifier and Type | Method and Description |
|---|---|
| private void | doJoinTransaction(boolean
whether to enforce the transaction
(i.e. whether failure to join is considered fatal) enforce)Join an existing transaction, if not already joined. |
| private void | enlistInCurrentTransaction()
Enlist this application-managed EntityManager in the current transaction. |
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] Method instance corresponding to
the interface method invoked on the proxy instance. The declaring
class of the Method object will be the interface that
the method was declared in, which may be a superinterface of the
proxy interface that the proxy class inherits the method through.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or args)null if interface method takes no arguments.
Arguments of primitive types are wrapped in instances of the
appropriate primitive wrapper class, such as
java.lang.Integer or java.lang.Boolean.Implements java. Processes a method invocation on a proxy instance and returns the result. |
| private boolean |
| containerManaged | back to summary |
|---|---|
| private final boolean containerManaged | |
| exceptionTranslator | back to summary |
|---|---|
| private final PersistenceExceptionTranslator exceptionTranslator
| |
| jta | back to summary |
|---|---|
| private final boolean jta | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| synchronizedWithTransaction | back to summary |
|---|---|
| private final boolean synchronizedWithTransaction | |
| target | back to summary |
|---|---|
| private final EntityManager target | |
| ExtendedEntityManagerInvocationHandler | back to summary |
|---|---|
| private ExtendedEntityManagerInvocationHandler(EntityManager target, PersistenceExceptionTranslator exceptionTranslator, Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) | |
| doJoinTransaction | back to summary |
|---|---|
| private void doJoinTransaction(boolean enforce) Join an existing transaction, if not already joined.
| |
| enlistInCurrentTransaction | back to summary |
|---|---|
| private void enlistInCurrentTransaction() Enlist this application-managed EntityManager in the current transaction. | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable Implements java. Doc from java. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
| |
| isJtaEntityManager | back to summary |
|---|---|
| private boolean isJtaEntityManager() | |
| Modifier and Type | Field and Description |
|---|---|
| public volatile boolean | |
| private final EntityManager | |
| private final PersistenceExceptionTranslator |
| Access | Constructor and Description |
|---|---|
| public | ExtendedEntityManagerSynchronization(EntityManager em, PersistenceExceptionTranslator exceptionTranslator)
|
| closeOnCompletion | back to summary |
|---|---|
| public volatile boolean closeOnCompletion | |
| entityManager | back to summary |
|---|---|
| private final EntityManager entityManager | |
| exceptionTranslator | back to summary |
|---|---|
| private final PersistenceExceptionTranslator exceptionTranslator
| |
| ExtendedEntityManagerSynchronization | back to summary |
|---|---|
| public ExtendedEntityManagerSynchronization(EntityManager em, PersistenceExceptionTranslator exceptionTranslator) | |
| afterCommit | back to summary |
|---|---|
| public void afterCommit() Overrides org. Overrides default org. Doc from org. Invoked after transaction commit. Can perform further operations right after the main transaction has successfully committed. Can e.g. commit further operations that are supposed to follow on a successful commit of the main transaction, like confirmation messages or emails. Note The transaction will have been committed already, but the
transactional resources might still be active and accessible. As a consequence,
any data access code triggered at this point will still "participate" in the
original transaction, allowing to perform some cleanup (with no commit following
anymore!), unless it explicitly declares that it needs to run in a separate
transaction. Hence: Use
| |
| afterCompletion | back to summary |
|---|---|
| public void afterCompletion(int status) Overrides org. Overrides default org. Doc from org. Invoked after transaction commit/rollback. Can perform resource cleanup after transaction completion. Note The transaction will have been committed or rolled back already,
but the transactional resources might still be active and accessible. As a
consequence, any data access code triggered at this point will still "participate"
in the original transaction, allowing to perform some cleanup (with no commit
following anymore!), unless it explicitly declares that it needs to run in a
separate transaction. Hence: Use
| |
| convertException | back to summary |
|---|---|
| private RuntimeException convertException(RuntimeException ex) | |
| flushResource | back to summary |
|---|---|
| protected void flushResource(EntityManagerHolder resourceHolder) Overrides org. Doc from org. Flush callback for the given resource holder.
| |
| getOrder | back to summary |
|---|---|
| public int getOrder() Overrides default org. Implements org. Doc from org. Get the order value of this object. Higher values are interpreted as lower priority. As a consequence,
the object with the lowest value has the highest priority (somewhat
analogous to Servlet Same order values will result in arbitrary sort positions for the affected objects.
| |
| shouldReleaseBeforeCompletion | back to summary |
|---|---|
| protected boolean shouldReleaseBeforeCompletion() Overrides org. Doc from org. Return whether this holder's resource should be released before
transaction completion ( Note that resources will only be released when they are
unbound from the thread ( The default implementation returns
| |