public class LocalEntityManagerFactoryBean extends AbstractEntityManagerFactoryBean
FactoryBean
that creates a JPA
EntityManagerFactory
according to JPA's standard
standalone bootstrap contract. This is the simplest 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
LocalContainerEntityManagerFactoryBean
definition based on the
JPA container contract is just a matter of configuration!
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. See the Java Persistence API specification and your persistence provider
documentation for setup details. Additionally, JPA properties can also be added
on this FactoryBean via AbstractEntityManagerFactoryBean.setJpaProperties(java.util.Properties)
/AbstractEntityManagerFactoryBean.setJpaPropertyMap(java.util.Map<java.lang.String, ?>)
.
Note: This FactoryBean has limited configuration power in terms of
the configuration that it is able to pass to the JPA provider. If you need
more flexible configuration options, consider using Spring's more powerful
LocalContainerEntityManagerFactoryBean
instead.
NOTE: Spring's JPA support requires JPA 2.1 or higher, as of Spring 5.0. JPA 1.0/2.0 based applications are still supported; however, a JPA 2.1 compliant persistence provider is needed at runtime.
AbstractEntityManagerFactoryBean.setJpaProperties(java.util.Properties)
,
AbstractEntityManagerFactoryBean.setJpaVendorAdapter(org.springframework.orm.jpa.JpaVendorAdapter)
,
JpaTransactionManager.setEntityManagerFactory(javax.persistence.EntityManagerFactory)
,
LocalContainerEntityManagerFactoryBean
,
JndiObjectFactoryBean
,
SharedEntityManagerBean
,
Persistence.createEntityManagerFactory(java.lang.String)
,
PersistenceProvider.createEntityManagerFactory(java.lang.String, java.util.Map)
,
Serialized Formlogger
OBJECT_TYPE_ATTRIBUTE
Constructor and Description |
---|
LocalEntityManagerFactoryBean() |
Modifier and Type | Method and Description |
---|---|
protected EntityManagerFactory |
createNativeEntityManagerFactory()
Initialize the EntityManagerFactory for the given configuration.
|
afterPropertiesSet, createEntityManagerFactoryProxy, createNativeEntityManager, destroy, getBeanClassLoader, getBootstrapExecutor, getDataSource, getEntityManagerInterface, getJpaDialect, getJpaPropertyMap, getJpaVendorAdapter, getNativeEntityManagerFactory, getObject, getObjectType, getPersistenceProvider, getPersistenceUnitInfo, getPersistenceUnitName, isSingleton, postProcessEntityManager, setBeanClassLoader, setBeanFactory, setBeanName, setBootstrapExecutor, setEntityManagerFactoryInterface, setEntityManagerInitializer, setEntityManagerInterface, setJpaDialect, setJpaProperties, setJpaPropertyMap, setJpaVendorAdapter, setPersistenceProvider, setPersistenceProviderClass, setPersistenceUnitName, translateExceptionIfPossible, writeReplace
protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException
createNativeEntityManagerFactory
in class AbstractEntityManagerFactoryBean
PersistenceException
- in case of JPA initialization errors