Class ExtendedEntityManagerCreator

java.lang.Object
org.springframework.orm.jpa.ExtendedEntityManagerCreator

public abstract class ExtendedEntityManagerCreator extends Object
Delegate for creating a variety of EntityManager proxies that follow the JPA spec's semantics for "extended" EntityManagers.

Supports several different variants of "extended" EntityManagers: in particular, an "application-managed extended EntityManager", as defined by EntityManagerFactory.createEntityManager(), as well as a "container-managed extended EntityManager", as defined by PersistenceContextType.EXTENDED.

The original difference between "application-managed" and "container-managed" was the need for explicit joining of an externally managed transaction through the EntityManager.joinTransaction() method in the "application" case versus the automatic joining on each user-level EntityManager operation in the "container" case. As of JPA 2.1, both join modes are available with both kinds of EntityManagers, so the difference between "application-" and "container-managed" is now primarily in the join mode default and in the restricted lifecycle of a container-managed EntityManager (i.e. tied to the object that it is injected into).

Since:
2.0
Author:
Juergen Hoeller, Rod Johnson, Mark Paluch
See Also:
  • Constructor Details

    • ExtendedEntityManagerCreator

      public ExtendedEntityManagerCreator()
  • Method Details

    • createApplicationManagedEntityManager

      public static EntityManager createApplicationManagedEntityManager(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo)
      Create an application-managed extended EntityManager proxy.
      Parameters:
      rawEntityManager - the raw EntityManager to decorate
      emfInfo - the EntityManagerFactoryInfo to obtain the JpaDialect and PersistenceUnitInfo from
      Returns:
      an application-managed EntityManager that can join transactions but does not participate in them automatically
    • createApplicationManagedEntityManager

      public static EntityManager createApplicationManagedEntityManager(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean synchronizedWithTransaction)
      Create an application-managed extended EntityManager proxy.
      Parameters:
      rawEntityManager - the raw EntityManager to decorate
      emfInfo - the EntityManagerFactoryInfo to obtain the JpaDialect and PersistenceUnitInfo from
      synchronizedWithTransaction - whether to automatically join ongoing transactions (according to the JPA 2.1 SynchronizationType rules)
      Returns:
      an application-managed EntityManager that can join transactions but does not participate in them automatically
      Since:
      4.0
    • createContainerManagedEntityManager

      public static EntityManager createContainerManagedEntityManager(EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo)
      Create a container-managed extended EntityManager proxy.
      Parameters:
      rawEntityManager - the raw EntityManager to decorate
      emfInfo - the EntityManagerFactoryInfo to obtain the JpaDialect and PersistenceUnitInfo from
      Returns:
      a container-managed EntityManager that will automatically participate in any managed transaction
    • createContainerManagedEntityManager

      public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf)
      Create a container-managed extended EntityManager proxy.
      Parameters:
      emf - the EntityManagerFactory to create the EntityManager with. If this implements the EntityManagerFactoryInfo interface, the corresponding JpaDialect and PersistenceUnitInfo will be detected accordingly.
      Returns:
      a container-managed EntityManager that will automatically participate in any managed transaction
      See Also:
    • createContainerManagedEntityManager

      public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf, @Nullable Map<?,?> properties)
      Create a container-managed extended EntityManager proxy.
      Parameters:
      emf - the EntityManagerFactory to create the EntityManager with. If this implements the EntityManagerFactoryInfo interface, the corresponding JpaDialect and PersistenceUnitInfo will be detected accordingly.
      properties - the properties to be passed into the createEntityManager call (may be null)
      Returns:
      a container-managed EntityManager that will automatically participate in any managed transaction
      See Also:
    • createContainerManagedEntityManager

      public static EntityManager createContainerManagedEntityManager(EntityManagerFactory emf, @Nullable Map<?,?> properties, boolean synchronizedWithTransaction)
      Create a container-managed extended EntityManager proxy.
      Parameters:
      emf - the EntityManagerFactory to create the EntityManager with. If this implements the EntityManagerFactoryInfo interface, the corresponding JpaDialect and PersistenceUnitInfo will be detected accordingly.
      properties - the properties to be passed into the createEntityManager call (may be null)
      synchronizedWithTransaction - whether to automatically join ongoing transactions (according to the JPA 2.1 SynchronizationType rules)
      Returns:
      a container-managed EntityManager that expects container-driven lifecycle management but may opt out of automatic transaction synchronization
      Since:
      4.0
      See Also: