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

public abstract Class AbstractEntityManagerFactoryBean

extends Object
implements FactoryBean<EntityManagerFactory>, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean, EntityManagerFactoryInfo, PersistenceExceptionTranslator, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.dao.support.PersistenceExceptionTranslator, org.springframework.orm.jpa.EntityManagerFactoryInfo, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.FactoryBean
Known Direct Subclasses
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean, org.springframework.orm.jpa.LocalEntityManagerFactoryBean
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .NotSerializableException, .ObjectInputStream, .ObjectStreamException, .Serializable, java.lang.reflect.InvocationHandler, .InvocationTargetException, .Method, .Proxy, java.util.HashMap, .LinkedHashSet, .Map, .Properties, .Set, java.util.concurrent.ExecutionException, .Future, java.util.function.Consumer, javax.sql.DataSource, jakarta.persistence.EntityManager, .EntityManagerFactory, .PersistenceException, .Query, .SynchronizationType, jakarta.persistence.spi.PersistenceProvider, .PersistenceUnitInfo, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.BeanUtils, org.springframework.beans.factory.BeanClassLoaderAware, .BeanFactory, .BeanFactoryAware, .BeanNameAware, .DisposableBean, .FactoryBean, .InitializingBean, org.springframework.core.task.AsyncTaskExecutor, org.springframework.dao.DataAccessException, org.springframework.dao.support.PersistenceExceptionTranslator, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils

Abstract org.springframework.beans.factory.FactoryBean that creates a local JPA jakarta.persistence.EntityManagerFactory instance within a Spring application context.

Encapsulates the common functionality between the different JPA bootstrap contracts (standalone as well as container).

Implements support for standard JPA configuration conventions as well as Spring's customizable JpaVendorAdapter mechanism, and controls the EntityManagerFactory's lifecycle.

This class also implements the org.springframework.dao.support.PersistenceExceptionTranslator interface, as autodetected by Spring's org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor, for AOP-based translation of native exceptions to Spring DataAccessExceptions. Hence, the presence of e.g. LocalEntityManagerFactoryBean automatically enables a PersistenceExceptionTranslationPostProcessor to translate JPA exceptions.

Authors
Juergen Hoeller, Rod Johnson
Since
2.0
See Also
LocalEntityManagerFactoryBean, LocalContainerEntityManagerFactoryBean

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AbstractEntityManagerFactoryBean.ManagedEntityManagerFactoryInvocationHandler

Dynamic proxy invocation handler for an EntityManagerFactory, returning a proxy EntityManager (if necessary) from createEntityManager methods.

private static class
AbstractEntityManagerFactoryBean.SerializedEntityManagerFactoryBeanReference

Minimal bean reference to the surrounding AbstractEntityManagerFactoryBean.

Field Summary

Modifier and TypeField and Description
private ClassLoader
private BeanFactory
private String
private AsyncTaskExecutor
private EntityManagerFactory
entityManagerFactory

Exposed client-level EntityManagerFactory proxy.

private Class<? extends EntityManagerFactory>
private Consumer<EntityManager>
private Class<? extends EntityManager>
private JpaDialect
private final Map<String, Object>
private JpaVendorAdapter
protected final Log
logger

Logger available to subclasses.

private EntityManagerFactory
nativeEntityManagerFactory

Raw EntityManagerFactory as returned by the PersistenceProvider.

private Future<EntityManagerFactory>
nativeEntityManagerFactoryFuture

Future for lazily initializing raw target EntityManagerFactory.

private PersistenceProvider
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

private EntityManagerFactory
protected EntityManagerFactory

Returns:

the EntityManagerFactory proxy
createEntityManagerFactoryProxy
(EntityManagerFactory
the EntityManagerFactory as returned by the persistence provider, if initialized already
emf
)

Create a proxy for the given EntityManagerFactory.

public EntityManager
createNativeEntityManager(Map<?, ?> properties)

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.createNativeEntityManager.

Create a native JPA EntityManager to be used as the framework-managed resource behind an application-level EntityManager handle.
protected abstract EntityManagerFactory

Returns:

the EntityManagerFactory instance returned by this FactoryBean
createNativeEntityManagerFactory
()

Subclasses must implement this method to create the EntityManagerFactory that will be returned by the getObject() method.

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Close the EntityManagerFactory on bean factory shutdown.
public ClassLoader
getBeanClassLoader()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getBeanClassLoader.

Return the ClassLoader that the application's beans are loaded with.
public AsyncTaskExecutor
getBootstrapExecutor()

Return the asynchronous executor for background bootstrapping, if any.

public DataSource
getDataSource()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getDataSource.

Return the JDBC DataSource that this EntityManagerFactory obtains its JDBC Connections from.
public Class<? extends EntityManager>
getEntityManagerInterface()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getEntityManagerInterface.

Return the (potentially vendor-specific) EntityManager interface that this factory's EntityManagers will implement.
public JpaDialect
getJpaDialect()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getJpaDialect.

Return the vendor-specific JpaDialect implementation for this EntityManagerFactory, or null if not known.
public Map<String, Object>
getJpaPropertyMap()

Allow Map access to the JPA properties to be passed to the persistence provider, with the option to add or override specific entries.

public JpaVendorAdapter
getJpaVendorAdapter()

Return the JpaVendorAdapter implementation for this EntityManagerFactory, or null if not known.

public EntityManagerFactory
public EntityManagerFactory
getObject()

Implements org.springframework.beans.factory.FactoryBean.getObject.

Return the singleton EntityManagerFactory.
public Class<? extends EntityManagerFactory>
getObjectType()

Implements org.springframework.beans.factory.FactoryBean.getObjectType.

Return the type of object that this FactoryBean creates, or null if not known in advance.
public PersistenceProvider
getPersistenceProvider()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getPersistenceProvider.

Return the underlying PersistenceProvider that the underlying EntityManagerFactory was created with.
public PersistenceUnitInfo
getPersistenceUnitInfo()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getPersistenceUnitInfo.

Return the PersistenceUnitInfo used to create this EntityManagerFactory, if the in-container API was used.
public String
getPersistenceUnitName()

Implements org.springframework.orm.jpa.EntityManagerFactoryInfo.getPersistenceUnitName.

Return the name of the persistence unit used to create this EntityManagerFactory, or null if it is an unnamed default.
pack-priv Object
invokeProxyMethod(Method method, Object[] args)

Delegate an incoming invocation from the proxy, dispatching to EntityManagerFactoryInfo or the native EntityManagerFactory accordingly.

public boolean
isSingleton()

Overrides default org.springframework.beans.factory.FactoryBean.isSingleton.

Is the object managed by this factory a singleton?
protected void
postProcessEntityManager(EntityManager
the EntityManager to post-process
rawEntityManager
)

Optional callback for post-processing the native EntityManager before active use.

private void
public void
setBeanClassLoader(ClassLoader
the owning class loader
classLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.
public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.
public void
setBeanName(String
the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.
name
)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

Set the name of the bean in the bean factory that created this bean.
public void
setBootstrapExecutor(AsyncTaskExecutor bootstrapExecutor)

Specify an asynchronous executor for background bootstrapping, e.g. a org.springframework.core.task.SimpleAsyncTaskExecutor.

public void
setEntityManagerFactoryInterface(Class<? extends EntityManagerFactory> emfInterface)

Specify the (potentially vendor-specific) EntityManagerFactory interface that this EntityManagerFactory proxy is supposed to implement.

public void
setEntityManagerInitializer(Consumer<EntityManager> entityManagerInitializer)

Specify a callback for customizing every EntityManager created by the exposed EntityManagerFactory.

public void
setEntityManagerInterface(Class<? extends EntityManager> emInterface)

Specify the (potentially vendor-specific) EntityManager interface that this factory's EntityManagers are supposed to implement.

public void
setJpaDialect(JpaDialect jpaDialect)

Specify the vendor-specific JpaDialect implementation to associate with this EntityManagerFactory.

public void
setJpaProperties(Properties jpaProperties)

Specify JPA properties, to be passed into Persistence.createEntityManagerFactory (if any).

public void
setJpaPropertyMap(Map<String, ?> jpaProperties)

Specify JPA properties as a Map, to be passed into Persistence.createEntityManagerFactory (if any).

public void
setJpaVendorAdapter(JpaVendorAdapter jpaVendorAdapter)

Specify the JpaVendorAdapter implementation for the desired JPA provider, if any.

public void
setPersistenceProvider(PersistenceProvider persistenceProvider)

Set the PersistenceProvider instance to use for creating the EntityManagerFactory.

public void
setPersistenceProviderClass(Class<? extends PersistenceProvider> persistenceProviderClass)

Set the PersistenceProvider implementation class to use for creating the EntityManagerFactory.

public void
setPersistenceUnitName(String persistenceUnitName)

Specify the name of the EntityManagerFactory configuration.

public DataAccessException
translateExceptionIfPossible(RuntimeException
a RuntimeException to translate
ex
)

Implements org.springframework.dao.support.PersistenceExceptionTranslator.translateExceptionIfPossible.

Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
protected Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait