public abstract class SharedEntityManagerCreator
extends java.lang.Object
javax.persistence.EntityManager
reference for a given javax.persistence.EntityManagerFactory
.
A shared EntityManager will behave just like an EntityManager fetched from an application server's JNDI environment, as defined by the JPA specification. It will delegate all calls to the current transactional EntityManager, if any; otherwise it will fall back to a newly created EntityManager per operation.
For a behavioral definition of such a shared transactional EntityManager,
see javax.persistence.PersistenceContextType#TRANSACTION
and its
discussion in the JPA spec document. This is also the default being used
for the annotation-based javax.persistence.PersistenceContext#type()
.
javax.persistence.PersistenceContext
,
javax.persistence.PersistenceContextType#TRANSACTION
,
JpaTransactionManager
,
ExtendedEntityManagerCreator
Modifier and Type | Class and Description |
---|---|
private static class |
SharedEntityManagerCreator.DeferredQueryInvocationHandler
Invocation handler that handles deferred Query objects created by
non-transactional createQuery invocations on a shared EntityManager.
|
private static class |
SharedEntityManagerCreator.SharedEntityManagerInvocationHandler
Invocation handler that delegates all calls to the current
transactional EntityManager, if any; else, it will fall back
to a newly created EntityManager per operation.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.Class<?>[] |
NO_ENTITY_MANAGER_INTERFACES |
private static java.util.Set<java.lang.String> |
queryTerminationMethods |
private static java.util.Set<java.lang.String> |
transactionRequiringMethods |
Constructor and Description |
---|
SharedEntityManagerCreator() |
Modifier and Type | Method and Description |
---|---|
static EntityManager |
createSharedEntityManager(EntityManagerFactory emf)
Create a transactional EntityManager proxy for the given EntityManagerFactory.
|
static EntityManager |
createSharedEntityManager(EntityManagerFactory emf,
java.util.Map<?,?> properties)
Create a transactional EntityManager proxy for the given EntityManagerFactory.
|
static EntityManager |
createSharedEntityManager(EntityManagerFactory emf,
java.util.Map<?,?> properties,
boolean synchronizedWithTransaction)
Create a transactional EntityManager proxy for the given EntityManagerFactory.
|
static EntityManager |
createSharedEntityManager(EntityManagerFactory emf,
java.util.Map<?,?> properties,
boolean synchronizedWithTransaction,
java.lang.Class<?>... entityManagerInterfaces)
Create a transactional EntityManager proxy for the given EntityManagerFactory.
|
static EntityManager |
createSharedEntityManager(EntityManagerFactory emf,
java.util.Map<?,?> properties,
java.lang.Class<?>... entityManagerInterfaces)
Create a transactional EntityManager proxy for the given EntityManagerFactory.
|
private static final java.lang.Class<?>[] NO_ENTITY_MANAGER_INTERFACES
private static final java.util.Set<java.lang.String> transactionRequiringMethods
private static final java.util.Set<java.lang.String> queryTerminationMethods
public static EntityManager createSharedEntityManager(EntityManagerFactory emf)
emf
- the EntityManagerFactory to delegate to.public static EntityManager createSharedEntityManager(EntityManagerFactory emf, java.util.Map<?,?> properties)
emf
- the EntityManagerFactory to delegate to.properties
- the properties to be passed into the
createEntityManager
call (may be null
)public static EntityManager createSharedEntityManager(EntityManagerFactory emf, java.util.Map<?,?> properties, boolean synchronizedWithTransaction)
emf
- the EntityManagerFactory to delegate to.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)public static EntityManager createSharedEntityManager(EntityManagerFactory emf, java.util.Map<?,?> properties, java.lang.Class<?>... entityManagerInterfaces)
emf
- EntityManagerFactory to obtain EntityManagers from as neededproperties
- the properties to be passed into the
createEntityManager
call (may be null
)entityManagerInterfaces
- the interfaces to be implemented by the
EntityManager. Allows the addition or specification of proprietary interfaces.public static EntityManager createSharedEntityManager(EntityManagerFactory emf, java.util.Map<?,?> properties, boolean synchronizedWithTransaction, java.lang.Class<?>... entityManagerInterfaces)
emf
- EntityManagerFactory to obtain EntityManagers from as neededproperties
- 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)entityManagerInterfaces
- the interfaces to be implemented by the
EntityManager. Allows the addition or specification of proprietary interfaces.