java.lang.Object | |
↳ | org.springframework.orm.jpa.AbstractEntityManagerFactoryBean |
Known Direct Subclasses |
Abstract FactoryBean
that
creates a local JPA javax.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 as well as
Spring's JpaVendorAdapter
abstraction, and controls the
EntityManagerFactory's lifecycle.
This class also implements the
PersistenceExceptionTranslator
interface, as autodetected by Spring's
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.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
logger | Logger available to subclasses | ||||||||||
nativeEntityManagerFactory | Raw EntityManagerFactory as returned by the PersistenceProvider |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
| |||||||||||
Close the EntityManagerFactory on bean factory shutdown.
| |||||||||||
Return the ClassLoader that the application's beans are loaded with.
| |||||||||||
Return the JDBC DataSource that this EntityManagerFactory
obtains its JDBC Connections from.
| |||||||||||
Return the (potentially vendor-specific) EntityManager interface
that this factory's EntityManagers will implement.
| |||||||||||
Return the vendor-specific JpaDialect implementation for this
EntityManagerFactory, or
null if not known. | |||||||||||
Allow Map access to the JPA properties to be passed to the persistence
provider, with the option to add or override specific entries.
| |||||||||||
Return the JpaVendorAdapter implementation for this
EntityManagerFactory, or
null if not known. | |||||||||||
Return the raw underlying EntityManagerFactory.
| |||||||||||
Return the singleton EntityManagerFactory.
| |||||||||||
Return the type of object that this FactoryBean creates,
or
null if not known in advance. | |||||||||||
Return the underlying PersistenceProvider that the underlying
EntityManagerFactory was created with.
| |||||||||||
Return the PersistenceUnitInfo used to create this
EntityManagerFactory, if the in-container API was used.
| |||||||||||
Return the name of the persistence unit used to create this
EntityManagerFactory, or
null if it is an unnamed default. | |||||||||||
Is the object managed by this factory a singleton? That is,
will
getObject() always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from | |||||||||||
Callback that supplies the bean
class loader to
a bean instance. | |||||||||||
Callback that supplies the owning factory to a bean instance.
| |||||||||||
Set the name of the bean in the bean factory that created this bean.
| |||||||||||
Specify the (potentially vendor-specific) EntityManagerFactory interface
that this EntityManagerFactory proxy is supposed to implement.
| |||||||||||
Specify the (potentially vendor-specific) EntityManager interface
that this factory's EntityManagers are supposed to implement.
| |||||||||||
Specify the vendor-specific JpaDialect implementation to associate with
this EntityManagerFactory.
| |||||||||||
Specify JPA properties, to be passed into
Persistence.createEntityManagerFactory (if any). | |||||||||||
Specify JPA properties as a Map, to be passed into
Persistence.createEntityManagerFactory (if any). | |||||||||||
Specify the JpaVendorAdapter implementation for the desired JPA provider,
if any.
| |||||||||||
Set the PersistenceProvider instance to use for creating the
EntityManagerFactory.
| |||||||||||
Set the PersistenceProvider implementation class to use for creating the
EntityManagerFactory.
| |||||||||||
Specify the name of the EntityManagerFactory configuration.
| |||||||||||
Implementation of the PersistenceExceptionTranslator interface, as
autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a proxy of the given EntityManagerFactory.
| |||||||||||
Subclasses must implement this method to create the EntityManagerFactory
that will be returned by the
getObject() method. | |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanClassLoaderAware
| |||||||||||
From interface
org.springframework.beans.factory.BeanFactoryAware
| |||||||||||
From interface
org.springframework.beans.factory.BeanNameAware
| |||||||||||
From interface
org.springframework.beans.factory.DisposableBean
| |||||||||||
From interface
org.springframework.beans.factory.FactoryBean
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.dao.support.PersistenceExceptionTranslator
| |||||||||||
From interface
org.springframework.orm.jpa.EntityManagerFactoryInfo
|
Logger available to subclasses
Raw EntityManagerFactory as returned by the PersistenceProvider
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
PersistenceException |
---|
Close the EntityManagerFactory on bean factory shutdown.
Return the ClassLoader that the application's beans are loaded with.
Proxies will be generated in this ClassLoader.
Return the JDBC DataSource that this EntityManagerFactory obtains its JDBC Connections from.
null
if not known
Return the (potentially vendor-specific) EntityManager interface that this factory's EntityManagers will implement.
A null
return value suggests that autodetection is supposed
to happen: either based on a target EntityManager
instance
or simply defaulting to javax.persistence.EntityManager
.
Return the vendor-specific JpaDialect implementation for this
EntityManagerFactory, or null
if not known.
Allow Map access to the JPA properties to be passed to the persistence provider, with the option to add or override specific entries.
Useful for specifying entries directly, for example via "jpaPropertyMap[myKey]".
Return the JpaVendorAdapter implementation for this
EntityManagerFactory, or null
if not known.
Return the raw underlying EntityManagerFactory.
null
)
Return the singleton EntityManagerFactory.
null
)Return the type of object that this FactoryBean creates,
or null
if not known in advance.
This allows one to check for specific types of beans without instantiating objects, for example on autowiring.
In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.
This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.
NOTE: Autowiring will simply ignore FactoryBeans that return
null
here. Therefore it is highly recommended to implement
this method properly, using the current state of the FactoryBean.
null
if not known at the time of the callReturn the underlying PersistenceProvider that the underlying EntityManagerFactory was created with.
null
if the standard JPA provider autodetection process
was used to configure the EntityManagerFactory
Return the PersistenceUnitInfo used to create this EntityManagerFactory, if the in-container API was used.
null
if the in-container contract was not used to
configure the EntityManagerFactory
Return the name of the persistence unit used to create this
EntityManagerFactory, or null
if it is an unnamed default.
If getPersistenceUnitInfo()
returns non-null, the result of
getPersistenceUnitName()
must be equal to the value returned by
PersistenceUnitInfo.getPersistenceUnitName()
.
Is the object managed by this factory a singleton? That is,
will getObject()
always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from getObject()
might get cached
by the owning BeanFactory. Hence, do not return true
unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
NOTE: This method returning false
does not
necessarily indicate that returned objects are independent instances.
An implementation of the extended SmartFactoryBean
interface
may explicitly indicate independent instances through its
isPrototype()
method. Plain FactoryBean
implementations which do not implement this extended interface are
simply assumed to always return independent instances if the
isSingleton()
implementation returns false
.
Callback that supplies the bean class loader
to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
afterPropertiesSet()
method or a custom init-method.
classLoader | the owning class loader; may be null in
which case a default ClassLoader must be used, for example
the ClassLoader obtained via
getDefaultClassLoader()
|
---|
Callback that supplies the owning factory to a bean instance.
Invoked after the population of normal bean properties
but before an initialization callback such as
afterPropertiesSet()
or a custom init-method.
beanFactory | owning BeanFactory (never null ).
The bean can immediately call methods on the factory. |
---|
Set the name of the bean in the bean factory that created this bean.
Invoked after population of normal bean properties but before an
init callback such as afterPropertiesSet()
or a custom init-method.
name | 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. |
---|
Specify the (potentially vendor-specific) EntityManagerFactory interface that this EntityManagerFactory proxy is supposed to implement.
The default will be taken from the specific JpaVendorAdapter, if any,
or set to the standard javax.persistence.EntityManagerFactory
interface else.
Specify the (potentially vendor-specific) EntityManager interface that this factory's EntityManagers are supposed to implement.
The default will be taken from the specific JpaVendorAdapter, if any,
or set to the standard javax.persistence.EntityManager
interface else.
Specify the vendor-specific JpaDialect implementation to associate with this EntityManagerFactory. This will be exposed through the EntityManagerFactoryInfo interface, to be picked up as default dialect by accessors that intend to use JpaDialect functionality.
Specify JPA properties, to be passed into
Persistence.createEntityManagerFactory
(if any).
Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
Specify JPA properties as a Map, to be passed into
Persistence.createEntityManagerFactory
(if any).
Can be populated with a "map" or "props" element in XML bean definitions.
Specify the JpaVendorAdapter implementation for the desired JPA provider, if any. This will initialize appropriate defaults for the given provider, such as persistence provider class and JpaDialect, unless locally overridden in this FactoryBean.
Set the PersistenceProvider instance to use for creating the EntityManagerFactory. If not specified, the persistence provider will be taken from the JpaVendorAdapter (if any) or determined by the persistence unit deployment descriptor (as far as possible).
getPersistenceProvider()
Set the PersistenceProvider implementation class to use for creating the EntityManagerFactory. If not specified, the persistence provider will be taken from the JpaVendorAdapter (if any) or retrieved through scanning (as far as possible).
getPersistenceProvider()
Specify the name of the EntityManagerFactory configuration.
Default is none, indicating the default EntityManagerFactory configuration. The persistence provider will throw an exception if ambiguous EntityManager configurations are found.
Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
Uses the dialect's conversion if possible; otherwise falls back to standard JPA exception conversion.
ex | a RuntimeException thrown |
---|
null
if the
exception could not be translated, as in this case it may result from
user code rather than an actual persistence problem)Create a proxy of the given EntityManagerFactory. We do this to be able to return transaction-aware proxies for application-managed EntityManagers, and to introduce the NamedEntityManagerFactory interface
emf | EntityManagerFactory as returned by the persistence provider |
---|
Subclasses must implement this method to create the EntityManagerFactory
that will be returned by the getObject()
method.
if the EntityManager cannot be created | |
PersistenceException |