Mainly intended for internal use within the framework.
| Modifier and Type | Class and Description |
|---|---|
| private static class | EntityManagerFactoryUtils.
Callback for resource cleanup at the end of a non-JPA transaction (e.g. when participating in a JtaTransactionManager transaction), fully synchronized with the ongoing transaction. |
| private static class | EntityManagerFactoryUtils.
Minimal callback that just closes the EntityManager at the end of the transaction. |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | ENTITY_MANAGER_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up JPA EntityManagers. |
| private static final Log |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | applyTransactionTimeout(Query
the JPA Query object query, EntityManagerFactory the JPA EntityManagerFactory that the Query was created for emf)Apply the current transaction timeout, if any, to the given JPA Query object. |
| private static void | cleanupTransaction(Object
arbitrary object that holds transaction data, if any
(as returned by prepareTransaction) transactionData, EntityManagerFactory the EntityManagerFactory that the EntityManager has been created with emf)Prepare a transaction on the given EntityManager, if possible. |
| public static void | closeEntityManager(EntityManager
the JPA EntityManager to close (may be em)null)Close the given JPA EntityManager, catching and logging any cleanup exceptions thrown. |
| public static DataAccessException | Returns: the corresponding DataAccessException instance, ornull if the exception should not be translatedruntime exception that occurred ex)Convert the given runtime exception to an appropriate exception from the
|
| public static EntityManager | Returns: the EntityManager, ornull if none foundthe EntityManagerFactory to create the EntityManager with emf, Map<?, ?> the properties to be passed into the properties)createEntityManager
call (may be null)Obtain a JPA EntityManager from the given factory. |
| public static EntityManager | Returns: the EntityManager, ornull if none foundthe EntityManagerFactory to create the EntityManager with 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)Obtain a JPA EntityManager from the given factory. |
| public static EntityManagerFactory | Returns: the EntityManagerFactorythe ListableBeanFactory to search beanFactory, String the name of the persistence unit (may be unitName)null or empty,
in which case a single bean of type EntityManagerFactory will be searched for)Find an EntityManagerFactory with the given name in the given Spring application context (represented as ListableBeanFactory). |
| public static EntityManager | Returns: the EntityManager, ornull if none foundthe EntityManagerFactory to create the EntityManager with emf)Obtain a JPA EntityManager from the given factory. |
| public static EntityManager | Returns: the EntityManager, ornull if none foundthe EntityManagerFactory to create the EntityManager with emf, Map<?, ?> the properties to be passed into the properties)createEntityManager
call (may be null)Obtain a JPA EntityManager from the given factory. |
| private static Object | Returns: an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction)the EntityManager to prepare em, EntityManagerFactory the EntityManagerFactory that the EntityManager has been created with emf)Prepare a transaction on the given EntityManager, if possible. |
| ENTITY_MANAGER_SYNCHRONIZATION_ORDER | back to summary |
|---|---|
| public static final int ENTITY_MANAGER_SYNCHRONIZATION_ORDER Order value for TransactionSynchronization objects that clean up JPA EntityManagers. Return DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100 to execute EntityManager cleanup before JDBC Connection cleanup, if any. | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| EntityManagerFactoryUtils | back to summary |
|---|---|
| public EntityManagerFactoryUtils() | |
| applyTransactionTimeout | back to summary |
|---|---|
| public static void applyTransactionTimeout(Query query, EntityManagerFactory emf) Apply the current transaction timeout, if any, to the given JPA Query object. This method sets the JPA query hint "jakarta.persistence.query.timeout" accordingly.
| |
| cleanupTransaction | back to summary |
|---|---|
| private static void cleanupTransaction(Object transactionData, EntityManagerFactory emf) Prepare a transaction on the given EntityManager, if possible.
| |
| closeEntityManager | back to summary |
|---|---|
| public static void closeEntityManager(EntityManager em) Close the given JPA EntityManager, catching and logging any cleanup exceptions thrown.
| |
| convertJpaAccessExceptionIfPossible | back to summary |
|---|---|
| public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) Convert the given runtime exception to an appropriate exception from the
The most important cases like object not found or optimistic locking failure are covered here. For more fine-granular conversion, JpaTransactionManager etc support sophisticated translation of exceptions via a JpaDialect.
| |
| doGetTransactionalEntityManager | back to summary |
|---|---|
| public static EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map<?, ?> properties) throws PersistenceException Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, e.g. when using JpaTransactionManager. Same as
| |
| doGetTransactionalEntityManager | back to summary |
|---|---|
| public static EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map<?, ?> properties, boolean synchronizedWithTransaction) throws PersistenceException Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, e.g. when using JpaTransactionManager. Same as
| |
| findEntityManagerFactory | back to summary |
|---|---|
| public static EntityManagerFactory findEntityManagerFactory(ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException Find an EntityManagerFactory with the given name in the given Spring application context (represented as ListableBeanFactory). The specified unit name will be matched against the configured
persistence unit, provided that a discovered EntityManagerFactory
implements the If no unit name has been given, this method will search for a default
EntityManagerFactory through
| |
| getTransactionalEntityManager | back to summary |
|---|---|
| public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf) throws DataAccessResourceFailureException Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, e.g. when using JpaTransactionManager. Note Will return
| |
| getTransactionalEntityManager | back to summary |
|---|---|
| public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, Map<?, ?> properties) throws DataAccessResourceFailureException Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, e.g. when using JpaTransactionManager. Note Will return
| |
| prepareTransaction | back to summary |
|---|---|
| private static Object prepareTransaction(EntityManager em, EntityManagerFactory emf) Prepare a transaction on the given EntityManager, if possible.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final JpaDialect | |
| private final boolean | |
| private final Object |
| Access | Constructor and Description |
|---|---|
| public | TransactionalEntityManagerSynchronization(EntityManagerHolder emHolder, EntityManagerFactory emf, Object txData, boolean newEm)
|
| Modifier and Type | Method and Description |
|---|---|
| protected void | cleanupResource(EntityManagerHolder
the resource holder to process resourceHolder, EntityManagerFactory the key that the ResourceHolder was bound for resourceKey, boolean whether the transaction has committed ( committed)true)
or rolled back (false)Overrides org. Perform a cleanup on the given resource (which is left bound to the thread). |
| protected void | flushResource(EntityManagerHolder
the resource holder to flush resourceHolder)Overrides org. Flush callback for the given resource holder. |
| public int | getOrder()
Overrides default org. Implements org. Get the order value of this object. |
| protected void | releaseResource(EntityManagerHolder
the resource holder to process resourceHolder, EntityManagerFactory the key that the ResourceHolder was bound for resourceKey)Overrides org. Release the given resource (after it has been unbound from the thread). |
| protected boolean | shouldUnbindAtCompletion()
Overrides org. Return whether this holder should be unbound at completion (or should rather be left bound to the thread after the transaction). |
| jpaDialect | back to summary |
|---|---|
| private final JpaDialect jpaDialect
| |
| newEntityManager | back to summary |
|---|---|
| private final boolean newEntityManager | |
| transactionData | back to summary |
|---|---|
| private final Object transactionData
| |
| TransactionalEntityManagerSynchronization | back to summary |
|---|---|
| public TransactionalEntityManagerSynchronization(EntityManagerHolder emHolder, EntityManagerFactory emf, Object txData, boolean newEm) | |
| cleanupResource | back to summary |
|---|---|
| protected void cleanupResource(EntityManagerHolder resourceHolder, EntityManagerFactory resourceKey, boolean committed) Overrides org. Doc from org. Perform a cleanup on the given resource (which is left bound to the thread).
| |
| 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.
| |
| releaseResource | back to summary |
|---|---|
| protected void releaseResource(EntityManagerHolder resourceHolder, EntityManagerFactory resourceKey) Overrides org. Doc from org. Release the given resource (after it has been unbound from the thread).
| |
| shouldUnbindAtCompletion | back to summary |
|---|---|
| protected boolean shouldUnbindAtCompletion() Overrides org. Doc from org. Return whether this holder should be unbound at completion (or should rather be left bound to the thread after the transaction). The default implementation returns
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | getOrder()
Overrides default org. Implements org. Get the order value of this object. |
| protected void | releaseResource(EntityManagerHolder
the resource holder to process resourceHolder, EntityManagerFactory the key that the ResourceHolder was bound for resourceKey)Overrides org. Release the given resource (after it has been unbound from the thread). |
| TransactionScopedEntityManagerSynchronization | back to summary |
|---|---|
| public TransactionScopedEntityManagerSynchronization(EntityManagerHolder emHolder, EntityManagerFactory emf) | |
| 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.
| |
| releaseResource | back to summary |
|---|---|
| protected void releaseResource(EntityManagerHolder resourceHolder, EntityManagerFactory resourceKey) Overrides org. Doc from org. Release the given resource (after it has been unbound from the thread).
| |