Class SpringBeanContainer

java.lang.Object
org.springframework.orm.hibernate5.SpringBeanContainer
All Implemented Interfaces:
org.hibernate.resource.beans.container.spi.BeanContainer, Stoppable

public final class SpringBeanContainer extends Object implements org.hibernate.resource.beans.container.spi.BeanContainer
Spring's implementation of Hibernate's BeanContainer SPI, delegating to a Spring ConfigurableListableBeanFactory.

Auto-configured by LocalSessionFactoryBean.setBeanFactory(org.springframework.beans.factory.BeanFactory), programmatically supported via LocalSessionFactoryBuilder.setBeanContainer(org.springframework.beans.factory.config.ConfigurableListableBeanFactory), and manually configurable through a "hibernate.resource.beans.container" entry in JPA properties, e.g.:

 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
   ...
   <property name="jpaPropertyMap">
           <map>
       <entry key="hibernate.resource.beans.container">
               <bean class="org.springframework.orm.hibernate5.SpringBeanContainer"/>
             </entry>
           </map>
   </property>
 </bean>
Or in Java-based JPA configuration:
 LocalContainerEntityManagerFactoryBean emfb = ...
 emfb.getJpaPropertyMap().put(AvailableSettings.BEAN_CONTAINER, new SpringBeanContainer(beanFactory));
 
Please note that Spring's LocalSessionFactoryBean is an immediate alternative to LocalContainerEntityManagerFactoryBean for common JPA purposes: The Hibernate SessionFactory will natively expose the JPA EntityManagerFactory interface as well, and Hibernate BeanContainer integration will be registered out of the box.
Since:
5.1
Author:
Juergen Hoeller
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.hibernate.resource.beans.container.spi.BeanContainer

    org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate a new SpringBeanContainer for the given bean factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    <B> org.hibernate.resource.beans.container.spi.ContainedBean<B>
    getBean(Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
     
    <B> org.hibernate.resource.beans.container.spi.ContainedBean<B>
    getBean(String name, Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringBeanContainer

      public SpringBeanContainer(ConfigurableListableBeanFactory beanFactory)
      Instantiate a new SpringBeanContainer for the given bean factory.
      Parameters:
      beanFactory - the Spring bean factory to delegate to
  • Method Details

    • getBean

      public <B> org.hibernate.resource.beans.container.spi.ContainedBean<B> getBean(Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
      Specified by:
      getBean in interface org.hibernate.resource.beans.container.spi.BeanContainer
    • getBean

      public <B> org.hibernate.resource.beans.container.spi.ContainedBean<B> getBean(String name, Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
      Specified by:
      getBean in interface org.hibernate.resource.beans.container.spi.BeanContainer
    • stop

      public void stop()
      Specified by:
      stop in interface Stoppable