public class SharedEntityManagerBean extends EntityManagerFactoryAccessor implements org.springframework.beans.factory.FactoryBean<EntityManager>, org.springframework.beans.factory.InitializingBean
FactoryBean
that exposes a shared JPA EntityManager
reference for a given EntityManagerFactory. Typically used for an EntityManagerFactory
created by LocalContainerEntityManagerFactoryBean
,
as direct alternative to a JNDI lookup for a Java EE server's EntityManager reference.
The 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.
Can be passed to DAOs that expect a shared EntityManager reference rather than an
EntityManagerFactory. Note that Spring's JpaTransactionManager
always needs an EntityManagerFactory in order to create new transactional EntityManager instances.
logger
Constructor and Description |
---|
SharedEntityManagerBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
EntityManager |
getObject() |
Class<? extends EntityManager> |
getObjectType() |
boolean |
isSingleton() |
void |
setEntityManagerInterface(Class<? extends EntityManager> entityManagerInterface)
Specify the EntityManager interface to expose.
|
void |
setSynchronizedWithTransaction(boolean synchronizedWithTransaction)
Set whether to automatically join ongoing transactions (according
to the JPA 2.1 SynchronizationType rules).
|
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, obtainEntityManagerFactory, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName
public void setEntityManagerInterface(Class<? extends EntityManager> entityManagerInterface)
Default is the EntityManager interface as defined by the
EntityManagerFactoryInfo, if available. Else, the standard
javax.persistence.EntityManager
interface will be used.
public void setSynchronizedWithTransaction(boolean synchronizedWithTransaction)
public final void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
@Nullable public EntityManager getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<EntityManager>
public Class<? extends EntityManager> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<EntityManager>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<EntityManager>