Save This Page
Home » spring-framework-2.5.6-with-dependencies » org.springframework » orm » jpa » [javadoc | source]
org.springframework.orm.jpa
abstract public class: EntityManagerFactoryUtils [javadoc | source]
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.

Field 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.
    Also see:
    org.springframework.jdbc.datasource.DataSourceUtils#CONNECTION_SYNCHRONIZATION_ORDER
 
Method from org.springframework.orm.jpa.EntityManagerFactoryUtils Summary:
closeEntityManager,   convertJpaAccessExceptionIfPossible,   doGetTransactionalEntityManager,   findEntityManagerFactory,   getTransactionalEntityManager,   getTransactionalEntityManager
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.orm.jpa.EntityManagerFactoryUtils Detail:
 public static  void closeEntityManager(EntityManager em) 
    Close the given JPA EntityManager, catching and logging any cleanup exceptions thrown.
 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. For more fine-granular conversion, JpaAccessor and JpaTransactionManager support sophisticated translation of exceptions via a JpaDialect.

 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, for example when using JpaTransactionManager.

    Same as getEntityManager, but throwing the original PersistenceException.

 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 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.

 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, for example when using JpaTransactionManager.

    Note: Will return null if no thread-bound EntityManager found!

 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, for example when using JpaTransactionManager.

    Note: Will return null if no thread-bound EntityManager found!