Class LocalContainerEntityManagerFactoryBean

java.lang.Object
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
All Implemented Interfaces:
Serializable, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, FactoryBean<EntityManagerFactory>, InitializingBean, ResourceLoaderAware, LoadTimeWeaverAware, PersistenceExceptionTranslator, EntityManagerFactoryInfo

public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManagerFactoryBean implements ResourceLoaderAware, LoadTimeWeaverAware
FactoryBean that creates a JPA EntityManagerFactory according to JPA's standard container bootstrap contract. This is the most powerful way to set up a shared JPA EntityManagerFactory in a Spring application context; the EntityManagerFactory can then be passed to JPA-based DAOs via dependency injection. Note that switching to a JNDI lookup or to a LocalEntityManagerFactoryBean definition is just a matter of configuration!

As with LocalEntityManagerFactoryBean, configuration settings are usually read in from a META-INF/persistence.xml config file, residing in the class path, according to the general JPA configuration contract. However, this FactoryBean is more flexible in that you can override the location of the persistence.xml file, specify the JDBC DataSources to link to, etc. Furthermore, it allows for pluggable class instrumentation through Spring's LoadTimeWeaver abstraction, instead of being tied to a special VM agent specified on JVM startup.

Internally, this FactoryBean parses the persistence.xml file itself and creates a corresponding PersistenceUnitInfo object (with further configuration merged in, such as JDBC DataSources and the Spring LoadTimeWeaver), to be passed to the chosen JPA PersistenceProvider. This corresponds to a local JPA container with full support for the standard JPA container contract.

The exposed EntityManagerFactory object will implement all the interfaces of the underlying native EntityManagerFactory returned by the PersistenceProvider, plus the EntityManagerFactoryInfo interface which exposes additional metadata as assembled by this FactoryBean.

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

    • LocalContainerEntityManagerFactoryBean

      public LocalContainerEntityManagerFactoryBean()
  • Method Details