java.lang.Object | |
↳ | org.springframework.orm.jpa.EntityManagerFactoryUtils |
Helper class featuring methods for JPA EntityManager handling, allowing for reuse of EntityManager instances within transactions. Also provides support for exception translation.
Mainly intended for internal use within the framework.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ENTITY_MANAGER_SYNCHRONIZATION_ORDER | Order value for TransactionSynchronization objects that clean up JPA EntityManagers. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Apply the current transaction timeout, if any, to the given JPA Query object.
| |||||||||||
Close the given JPA EntityManager,
catching and logging any cleanup exceptions thrown.
| |||||||||||
Convert the given runtime exception to an appropriate exception from the
org.springframework.dao hierarchy. | |||||||||||
Obtain a JPA EntityManager from the given factory.
| |||||||||||
Find an EntityManagerFactory with the given name in the given
Spring application context (represented as ListableBeanFactory).
| |||||||||||
Obtain a JPA EntityManager from the given factory.
| |||||||||||
Obtain a JPA EntityManager from the given factory.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
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.
Apply the current transaction timeout, if any, to the given JPA Query object.
This method sets the JPA 2.0 query hints "javax.persistence.lock.timeout" and "javax.persistence.query.timeout" accordingly.
query | the JPA Query object |
---|---|
emf | JPA EntityManagerFactory that the Query was created for |
Close the given JPA EntityManager, catching and logging any cleanup exceptions thrown.
em | the JPA EntityManager to close (may be null ) |
---|
Convert the given runtime exception to an appropriate exception from the
org.springframework.dao
hierarchy.
Return null if no translation is appropriate: any other exception may
have resulted from user code, and should not be translated.
The most important cases like object not found or optimistic locking failure are covered here. For more fine-granular conversion, JpaAccessor and JpaTransactionManager support sophisticated translation of exceptions via a JpaDialect.
ex | runtime exception that occured |
---|
null
if the exception should not be translated
Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, for example when using JpaTransactionManager.
Same as getEntityManager
, but throwing the original PersistenceException.
emf | EntityManagerFactory to create the EntityManager with |
---|---|
properties | the properties to be passed into the createEntityManager
call (may be null ) |
null
if none foundif the EntityManager couldn't be created | |
PersistenceException |
JpaTransactionManager
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
peristence unit, provided that a discovered EntityManagerFactory
implements the EntityManagerFactoryInfo
interface. If not,
the persistence unit name will be matched against the Spring bean name,
assuming that the EntityManagerFactory bean names follow that convention.
beanFactory | the ListableBeanFactory to search |
---|---|
unitName | the name of the persistence unit (never empty) |
NoSuchBeanDefinitionException | if there is no such EntityManagerFactory in the context |
---|
Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, for example when using JpaTransactionManager.
Note: Will return null
if no thread-bound EntityManager found!
emf | EntityManagerFactory to create the EntityManager with |
---|---|
properties | the properties to be passed into the createEntityManager
call (may be null ) |
null
if none foundDataAccessResourceFailureException | if the EntityManager couldn't be obtained |
---|
Obtain a JPA EntityManager from the given factory. Is aware of a corresponding EntityManager bound to the current thread, for example when using JpaTransactionManager.
Note: Will return null
if no thread-bound EntityManager found!
emf | EntityManagerFactory to create the EntityManager with |
---|
null
if none foundDataAccessResourceFailureException | if the EntityManager couldn't be obtained |
---|