org.springframework.orm.jpa
Class LocalEntityManagerFactoryBean
java.lang.Object
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
org.springframework.orm.jpa.LocalEntityManagerFactoryBean
- All Implemented Interfaces:
- DisposableBean, FactoryBean, InitializingBean, PersistenceExceptionTranslator, EntityManagerFactoryInfo
public class LocalEntityManagerFactoryBean
- extends AbstractEntityManagerFactoryBean
FactoryBean that creates a local JPA EntityManagerFactory instance according
to JPA's standard standalone bootstrap contract.
Behaves like a EntityManagerFactory instance when used as bean reference, e.g.
for JpaTemplate's "entityManagerFactory" property. Note that switching to
LocalContainerEntityManagerFactoryBean or JndiObjectFactoryBean is just a matter
of configuration! The typical usage will be to register this as singleton in an
application context, and give bean references to application services that need it.
Configuration settings are usually read from a META-INF/persistence.xml
config file, residing in the class path, according to the JPA standalone bootstrap
contract. Additionally, most JPA providers will require a special VM agent
(specified on JVM startup) that allows them to instrument application classes.
See the Java Persistence API specification and your provider documentation for details.
This EntityManagerFactory bootstrap is appropriate for standalone applications
that solely use JPA for data access. If you want to set up your persistence provider
for global transactions that span multiple resources, you will need to either deploy
it into a full Java EE 5 application server and access the deployed EntityManagerFactory
via JNDI (-> JndiObjectFactoryBean), or use Spring's LocalContainerEntityManagerFactoryBean
with appropriate configuration for local setup according to JPA's container contract.
Note: This FactoryBean has limited configuration power in terms of what it can
pass to the JPA provider. If you need more flexible configuration, for example
passing a Spring-managed JDBC DataSource to the JPA provider, consider using
Spring's LocalContainerEntityManagerFactoryBean instead.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Rod Johnson
- See Also:
AbstractEntityManagerFactoryBean.setJpaProperties(java.util.Properties)
,
AbstractEntityManagerFactoryBean.setJpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter)
,
EntityManagerFactoryAccessor.setEntityManagerFactory(javax.persistence.EntityManagerFactory)
,
JpaTransactionManager.setEntityManagerFactory(javax.persistence.EntityManagerFactory)
,
LocalContainerEntityManagerFactoryBean
,
JndiObjectFactoryBean
,
SharedEntityManagerBean
,
Persistence.createEntityManagerFactory(java.lang.String)
,
PersistenceProvider.createEntityManagerFactory(java.lang.String, java.util.Map)
Method Summary |
protected javax.persistence.EntityManagerFactory |
createNativeEntityManagerFactory()
Initialize the EntityManagerFactory for the given configuration. |
Methods inherited from class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean |
afterPropertiesSet, createEntityManagerFactoryProxy, destroy, getDataSource, getEntityManagerInterface, getJpaDialect, getJpaPropertyMap, getNativeEntityManagerFactory, getObject, getObjectType, getPersistenceProvider, getPersistenceUnitInfo, getPersistenceUnitName, isSingleton, setEntityManagerInterface, setJpaDialect, setJpaProperties, setJpaPropertyMap, setJpaVendorAdapter, setPersistenceProvider, setPersistenceProviderClass, setPersistenceUnitName, translateExceptionIfPossible |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LocalEntityManagerFactoryBean
public LocalEntityManagerFactoryBean()
createNativeEntityManagerFactory
protected javax.persistence.EntityManagerFactory createNativeEntityManagerFactory()
throws javax.persistence.PersistenceException
- Initialize the EntityManagerFactory for the given configuration.
- Specified by:
createNativeEntityManagerFactory
in class AbstractEntityManagerFactoryBean
- Returns:
- EntityManagerFactory instance returned by this FactoryBean
- Throws:
javax.persistence.PersistenceException
- in case of JPA initialization errors
Copyright © 2002-2007 The Spring Framework.