Class SharedEntityManagerBean
java.lang.Object
org.springframework.orm.jpa.EntityManagerFactoryAccessor
org.springframework.orm.jpa.support.SharedEntityManagerBean
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.FactoryBean<EntityManager>
,org.springframework.beans.factory.InitializingBean
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 Jakarta 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.
-
Field Summary
Fields inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor
logger
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Class<? extends EntityManager>
boolean
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).Methods inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, obtainEntityManagerFactory, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName
-
Constructor Details
-
SharedEntityManagerBean
public SharedEntityManagerBean()
-
-
Method Details
-
setEntityManagerInterface
Specify the EntityManager interface to expose.Default is the EntityManager interface as defined by the EntityManagerFactoryInfo, if available. Else, the standard
jakarta.persistence.EntityManager
interface will be used. -
setSynchronizedWithTransaction
public void setSynchronizedWithTransaction(boolean synchronizedWithTransaction) Set whether to automatically join ongoing transactions (according to the JPA 2.1 SynchronizationType rules). Default is "true". -
afterPropertiesSet
public final void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
getObject
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<EntityManager>
-
getObjectType
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<EntityManager>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<EntityManager>
-