Class AbstractEntityManagerFactoryBean

  • java.lang.Object
    • org.springframework.orm.jpa.AbstractEntityManagerFactoryBean
    • Field Detail

      • logger

        protected final Log logger
        Logger available to subclasses.
    • Constructor Detail

      • AbstractEntityManagerFactoryBean

        public AbstractEntityManagerFactoryBean()
    • Method Detail

      • setPersistenceProviderClass

        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).
        See Also:
        JpaVendorAdapter.getPersistenceProvider(), PersistenceProvider, Persistence
      • getPersistenceProvider

        public PersistenceProvider getPersistenceProvider()
        Description copied from interface: EntityManagerFactoryInfo
        Return the underlying PersistenceProvider that the underlying EntityManagerFactory was created with.
        Specified by:
        getPersistenceProvider in interface EntityManagerFactoryInfo
        the PersistenceProvider used to create this EntityManagerFactory, or null if the standard JPA provider autodetection process was used to configure the EntityManagerFactory
      • setPersistenceUnitName

        public void setPersistenceUnitName(@Nullable
                                           java.lang.String persistenceUnitName)
        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.

        See Also:
      • getJpaPropertyMap

        public java.util.Map<java.lang.String,java.lang.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.

        Useful for specifying entries directly, for example via "jpaPropertyMap[myKey]".

      • setEntityManagerFactoryInterface

        public void setEntityManagerFactoryInterface(java.lang.Class<? extends EntityManagerFactory> emfInterface)
        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.

        See Also:
      • getEntityManagerInterface

        public java.lang.Class<? extends EntityManager> getEntityManagerInterface()
        Description copied from interface: EntityManagerFactoryInfo
        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.

        Specified by:
        getEntityManagerInterface in interface EntityManagerFactoryInfo
      • setJpaDialect

        public void setJpaDialect(@Nullable
                                  JpaDialect jpaDialect)
        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.
        See Also:
      • setJpaVendorAdapter

        public void setJpaVendorAdapter(@Nullable
                                        JpaVendorAdapter jpaVendorAdapter)
        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.
      • getJpaVendorAdapter

        public JpaVendorAdapter getJpaVendorAdapter()
        Return the JpaVendorAdapter implementation for this EntityManagerFactory, or null if not known.
      • setBootstrapExecutor

        public void setBootstrapExecutor(@Nullable
                                         AsyncTaskExecutor bootstrapExecutor)
        Specify an asynchronous executor for background bootstrapping, e.g. a SimpleAsyncTaskExecutor.

        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.

      • getBootstrapExecutor

        public AsyncTaskExecutor getBootstrapExecutor()
        Return the asynchronous executor for background bootstrapping, if any.
      • setBeanName

        public void setBeanName(java.lang.String name)
        Description copied from interface: BeanNameAware
        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 InitializingBean.afterPropertiesSet() or a custom init-method.

        Specified by:
        setBeanName in interface BeanNameAware
        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.
      • createEntityManagerFactoryProxy

        protected EntityManagerFactory createEntityManagerFactoryProxy(@Nullable
                                                                       EntityManagerFactory emf)
        Create a proxy for the given EntityManagerFactory. We do this to be able to return a transaction-aware proxy for an application-managed EntityManager.
        emf - the EntityManagerFactory as returned by the persistence provider, if initialized already
        the EntityManagerFactory proxy
      • createNativeEntityManagerFactory

        protected abstract EntityManagerFactory createNativeEntityManagerFactory()
                                                                          throws PersistenceException
        Subclasses must implement this method to create the EntityManagerFactory that will be returned by the getObject() method.
        the EntityManagerFactory instance returned by this FactoryBean
        PersistenceException - if the EntityManager cannot be created
      • getPersistenceUnitInfo

        public PersistenceUnitInfo getPersistenceUnitInfo()
        Description copied from interface: EntityManagerFactoryInfo
        Return the PersistenceUnitInfo used to create this EntityManagerFactory, if the in-container API was used.
        Specified by:
        getPersistenceUnitInfo in interface EntityManagerFactoryInfo
        the PersistenceUnitInfo used to create this EntityManagerFactory, or null if the in-container contract was not used to configure the EntityManagerFactory
      • getObjectType

        public java.lang.Class<? extends EntityManagerFactory> getObjectType()
        Description copied from interface: FactoryBean
        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.

        Specified by:
        getObjectType in interface FactoryBean<EntityManagerFactory>
        the type of object that this FactoryBean creates, or null if not known at the time of the call
        See Also:
      • isSingleton

        public boolean isSingleton()
        Description copied from interface: 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.

        Specified by:
        isSingleton in interface FactoryBean<EntityManagerFactory>
        whether the exposed object is a singleton
        See Also:
        FactoryBean.getObject(), SmartFactoryBean.isPrototype()
      • destroy

        public void destroy()
        Close the EntityManagerFactory on bean factory shutdown.
        Specified by:
        destroy in interface DisposableBean
      • writeReplace

        protected java.lang.Object writeReplace()