| java.lang.Object org.springframework.orm.jpa.EntityManagerFactoryUtils
EntityManagerFactoryUtils | abstract public class EntityManagerFactoryUtils (Code) | | 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.
author: Juergen Hoeller since: 2.0 |
Method Summary | |
public static DataAccessException | convertJpaAccessExceptionIfPossible(RuntimeException ex) 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. | public static EntityManager | doGetTransactionalEntityManager(EntityManagerFactory emf, Map properties) Obtain a JPA EntityManager from the given factory. | public static EntityManagerFactory | findEntityManagerFactory(ListableBeanFactory beanFactory, String unitName) 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. | public static EntityManager | getTransactionalEntityManager(EntityManagerFactory emf) Obtain a JPA EntityManager from the given factory. | public static EntityManager | getTransactionalEntityManager(EntityManagerFactory emf, Map properties) Obtain a JPA EntityManager from the given factory. |
convertJpaAccessExceptionIfPossible | public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex)(Code) | | 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.
Parameters: ex - runtime exception that occured the corresponding DataAccessException instance,or null if the exception should not be translated |
doGetTransactionalEntityManager | public static EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map properties) throws PersistenceException(Code) | | 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.
Parameters: emf - EntityManagerFactory to create the EntityManager with Parameters: properties - the properties to be passed into the createEntityManager call (may be null ) the EntityManager, or null if none found throws: javax.persistence.PersistenceException - if the EntityManager couldn't be created See Also: EntityManagerFactoryUtils.getTransactionalEntityManager(javax.persistence.EntityManagerFactory) See Also: JpaTransactionManager |
findEntityManagerFactory | public static EntityManagerFactory findEntityManagerFactory(ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException(Code) | | 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.
Parameters: beanFactory - the ListableBeanFactory to search Parameters: unitName - the name of the persistence unit (never empty) the EntityManagerFactory throws: NoSuchBeanDefinitionException - if there is no such EntityManagerFactory in the context See Also: EntityManagerFactoryInfo.getPersistenceUnitName |
getTransactionalEntityManager | public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf) throws DataAccessResourceFailureException(Code) | | 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!
Parameters: emf - EntityManagerFactory to create the EntityManager with the EntityManager, or null if none found throws: DataAccessResourceFailureException - if the EntityManager couldn't be obtained See Also: JpaTransactionManager |
getTransactionalEntityManager | public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, Map properties) throws DataAccessResourceFailureException(Code) | | 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!
Parameters: emf - EntityManagerFactory to create the EntityManager with Parameters: properties - the properties to be passed into the createEntityManager call (may be null ) the EntityManager, or null if none found throws: DataAccessResourceFailureException - if the EntityManager couldn't be obtained See Also: JpaTransactionManager |
|
|