|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.jpa.EntityManagerFactoryUtils
public abstract class 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.
Field Summary | |
---|---|
static int |
ENTITY_MANAGER_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up JPA EntityManagers. |
Constructor Summary | |
---|---|
EntityManagerFactoryUtils()
|
Method Summary | |
---|---|
static DataAccessException |
convertJpaAccessExceptionIfPossible(RuntimeException ex)
Convert the given runtime exception to an appropriate exception from the org.springframework.dao hierarchy. |
static javax.persistence.EntityManager |
doGetTransactionalEntityManager(javax.persistence.EntityManagerFactory emf,
Map properties)
Obtain a JPA EntityManager from the given factory. |
static javax.persistence.EntityManagerFactory |
findEntityManagerFactory(ListableBeanFactory beanFactory,
String unitName)
Find an EntityManagerFactory with the given name in the given Spring application context (represented as ListableBeanFactory). |
static javax.persistence.EntityManager |
getTransactionalEntityManager(javax.persistence.EntityManagerFactory emf)
Obtain a JPA EntityManager from the given factory. |
static javax.persistence.EntityManager |
getTransactionalEntityManager(javax.persistence.EntityManagerFactory emf,
Map properties)
Obtain a JPA EntityManager from the given factory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ENTITY_MANAGER_SYNCHRONIZATION_ORDER
Constructor Detail |
---|
public EntityManagerFactoryUtils()
Method Detail |
---|
public static javax.persistence.EntityManagerFactory findEntityManagerFactory(ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException
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 searchunitName
- the name of the persistence unit (never empty)
NoSuchBeanDefinitionException
- if there is no such EntityManagerFactory in the contextEntityManagerFactoryInfo.getPersistenceUnitName()
public static javax.persistence.EntityManager getTransactionalEntityManager(javax.persistence.EntityManagerFactory emf) throws DataAccessResourceFailureException
Note: Will return null
if no thread-bound EntityManager found!
emf
- EntityManagerFactory to create the EntityManager with
null
if none found
DataAccessResourceFailureException
- if the EntityManager couldn't be obtainedJpaTransactionManager
public static javax.persistence.EntityManager getTransactionalEntityManager(javax.persistence.EntityManagerFactory emf, Map properties) throws DataAccessResourceFailureException
Note: Will return null
if no thread-bound EntityManager found!
emf
- EntityManagerFactory to create the EntityManager withproperties
- the properties to be passed into the createEntityManager
call (may be null
)
null
if none found
DataAccessResourceFailureException
- if the EntityManager couldn't be obtainedJpaTransactionManager
public static javax.persistence.EntityManager doGetTransactionalEntityManager(javax.persistence.EntityManagerFactory emf, Map properties) throws javax.persistence.PersistenceException
Same as getEntityManager
, but throwing the original PersistenceException.
emf
- EntityManagerFactory to create the EntityManager withproperties
- the properties to be passed into the createEntityManager
call (may be null
)
null
if none found
javax.persistence.PersistenceException
- if the EntityManager couldn't be createdgetTransactionalEntityManager(javax.persistence.EntityManagerFactory)
,
JpaTransactionManager
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex)
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
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |