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
This class also implements the
interface, as autodetected by Spring's
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.
public void setPersistenceProviderClass(java.lang.Class<? extends PersistenceProvider> persistenceProviderClass)
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).
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).
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 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.
EntityManagerFactory initialization will then switch into background
bootstrap mode, with a EntityManagerFactory proxy immediately returned for
injection purposes instead of waiting for the JPA provider's bootstrapping to complete.
However, note that the first actual call to a EntityManagerFactory method will
then block until the JPA provider's bootstrapping completed, if not ready by then.
For maximum benefit, make sure to avoid early EntityManagerFactory calls
in init methods of related beans, even for metadata introspection purposes.
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.
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.
Is the object managed by this factory a singleton? That is,
will FactoryBean.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
SmartFactoryBean.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.
The default implementation returns true, since a
FactoryBean typically manages a singleton instance.