spring-orm

org.springframework.orm.jpa.support
Class SharedEntityManagerBean

java.lang.Object
  extended by org.springframework.orm.jpa.EntityManagerFactoryAccessor
      extended by org.springframework.orm.jpa.support.SharedEntityManagerBean
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.FactoryBean<javax.persistence.EntityManager>, org.springframework.beans.factory.InitializingBean

public class SharedEntityManagerBean
extends EntityManagerFactoryAccessor
implements org.springframework.beans.factory.FactoryBean<javax.persistence.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 5 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.

Since:
2.0
Author:
Juergen Hoeller
See Also:
EntityManagerFactoryAccessor.setEntityManagerFactory(javax.persistence.EntityManagerFactory), setEntityManagerInterface(java.lang.Class), LocalEntityManagerFactoryBean, JpaTransactionManager

Field Summary
 
Fields inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor
logger
 
Constructor Summary
SharedEntityManagerBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 javax.persistence.EntityManager getObject()
           
 java.lang.Class<? extends javax.persistence.EntityManager> getObjectType()
           
 boolean isSingleton()
           
 void setEntityManagerInterface(java.lang.Class<? extends javax.persistence.EntityManager> entityManagerInterface)
          Specify the EntityManager interface to expose.
 
Methods inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SharedEntityManagerBean

public SharedEntityManagerBean()
Method Detail

setEntityManagerInterface

public void setEntityManagerInterface(java.lang.Class<? extends javax.persistence.EntityManager> entityManagerInterface)
Specify the EntityManager interface to expose.

Default is the EntityManager interface as defined by the EntityManagerFactoryInfo, if available. Else, the standard javax.persistence.EntityManager interface will be used.

See Also:
EntityManagerFactoryInfo.getEntityManagerInterface(), EntityManager

afterPropertiesSet

public final void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

getObject

public javax.persistence.EntityManager getObject()
Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean<javax.persistence.EntityManager>

getObjectType

public java.lang.Class<? extends javax.persistence.EntityManager> getObjectType()
Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean<javax.persistence.EntityManager>

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface org.springframework.beans.factory.FactoryBean<javax.persistence.EntityManager>

spring-orm