Top Description Fields Constructors Methods
org.springframework.orm.jpa

public Class LocalEntityManagerFactoryBean

extends AbstractEntityManagerFactoryBean
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
jakarta.persistence.EntityManagerFactory, .Persistence, .PersistenceException, jakarta.persistence.spi.PersistenceProvider

org.springframework.beans.factory.FactoryBean that creates a JPA jakarta.persistence.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 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. 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 setup details.

This EntityManagerFactory bootstrap is appropriate for standalone applications which solely use JPA for data access. If you want to set up your persistence provider for an external DataSource and/or for global transactions which span multiple resources, you will need to either deploy it into a full Jakarta EE application server and access the deployed EntityManagerFactory via JNDI, 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 configuration it is able to 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 more powerful LocalContainerEntityManagerFactoryBean instead.

Authors
Juergen Hoeller, Rod Johnson
Since
2.0
See Also
setJpaProperties, setJpaVendorAdapter, JpaTransactionManager#setEntityManagerFactory, LocalContainerEntityManagerFactoryBean, org.springframework.jndi.JndiObjectFactoryBean, org.springframework.orm.jpa.support.SharedEntityManagerBean, jakarta.persistence.Persistence#createEntityManagerFactory, jakarta.persistence.spi.PersistenceProvider#createEntityManagerFactory

Field Summary

Inherited from org.springframework.orm.jpa.AbstractEntityManagerFactoryBean:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected EntityManagerFactory
createNativeEntityManagerFactory()

Implements abstract org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.createNativeEntityManagerFactory.

Initialize the EntityManagerFactory for the given configuration.
Inherited from org.springframework.orm.jpa.AbstractEntityManagerFactoryBean:
afterPropertiesSetcreateEntityManagerFactoryProxycreateNativeEntityManagerdestroygetBeanClassLoadergetBootstrapExecutorgetDataSourcegetEntityManagerInterfacegetJpaDialectgetJpaPropertyMapgetJpaVendorAdaptergetNativeEntityManagerFactorygetObjectgetObjectTypegetPersistenceProvidergetPersistenceUnitInfogetPersistenceUnitNameinvokeProxyMethodisSingletonpostProcessEntityManagersetBeanClassLoadersetBeanFactorysetBeanNamesetBootstrapExecutorsetEntityManagerFactoryInterfacesetEntityManagerInitializersetEntityManagerInterfacesetJpaDialectsetJpaPropertiessetJpaPropertyMapsetJpaVendorAdaptersetPersistenceProvidersetPersistenceProviderClasssetPersistenceUnitNametranslateExceptionIfPossiblewriteReplace

Constructor Detail

LocalEntityManagerFactoryBeanback to summary
public LocalEntityManagerFactoryBean()

Method Detail

createNativeEntityManagerFactoryback to summary
protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException

Implements abstract org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.createNativeEntityManagerFactory.

Initialize the EntityManagerFactory for the given configuration.

Returns:EntityManagerFactory

Doc from org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.createNativeEntityManagerFactory.

the EntityManagerFactory instance returned by this FactoryBean

Annotations
@Override
Exceptions
PersistenceException:
in case of JPA initialization errors