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

public final Class SpringBeanContainer

extends Object
implements BeanContainer
Class Inheritance
All Implemented Interfaces
org.hibernate.resource.beans.container.spi.BeanContainer, org.hibernate.service.spi.Stoppable
Imports
java.util.Map, java.util.function.Consumer, org.apache.commons.logging.Log, .LogFactory, org.hibernate.resource.beans.container.spi.BeanContainer, .ContainedBean, org.hibernate.resource.beans.spi.BeanInstanceProducer, org.hibernate.type.spi.TypeBootstrapContext, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanCreationException, org.springframework.beans.factory.config.AutowireCapableBeanFactory, .ConfigurableListableBeanFactory, org.springframework.lang.Nullable, org.springframework.util.Assert, .ConcurrentReferenceHashMap

Spring's implementation of Hibernate's BeanContainer SPI, delegating to a Spring ConfigurableListableBeanFactory.

Auto-configured by LocalSessionFactoryBean#setBeanFactory, programmatically supported via LocalSessionFactoryBuilder#setBeanContainer, 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 org.springframework.orm.jpa.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.
Author
Juergen Hoeller
Since
5.1
See Also
LocalSessionFactoryBean#setBeanFactory, LocalSessionFactoryBuilder#setBeanContainer, org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setJpaPropertyMap, org.hibernate.cfg.AvailableSettings#BEAN_CONTAINER

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final Map<Object, SpringBeanContainer.SpringContainedBean<?>>
private final ConfigurableListableBeanFactory
private static final Log

Constructor Summary

AccessConstructor and Description
public
SpringBeanContainer(ConfigurableListableBeanFactory
the Spring bean factory to delegate to
beanFactory
)

Instantiate a new SpringBeanContainer for the given bean factory.

Method Summary

Modifier and TypeMethod and Description
private SpringBeanContainer.SpringContainedBean<?>
createBean(Class<?> beanType, BeanContainer.LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer)

private SpringBeanContainer.SpringContainedBean<?>
createBean(String name, Class<?> beanType, BeanContainer.LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer)

public <B> ContainedBean<B>
public <B> ContainedBean<B>
public void
stop()

Implements org.hibernate.service.spi.Stoppable.stop.

Stop phase notification

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanCacheback to summary
private final Map<Object, SpringBeanContainer.SpringContainedBean<?>> beanCache
beanFactoryback to summary
private final ConfigurableListableBeanFactory beanFactory
loggerback to summary
private static final Log logger

Constructor Detail

SpringBeanContainerback to summary
public SpringBeanContainer(ConfigurableListableBeanFactory beanFactory)

Instantiate a new SpringBeanContainer for the given bean factory.

Parameters
beanFactory:ConfigurableListableBeanFactory

the Spring bean factory to delegate to

Method Detail

createBeanback to summary
private SpringBeanContainer.SpringContainedBean<?> createBean(Class<?> beanType, BeanContainer.LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer)
createBeanback to summary
private SpringBeanContainer.SpringContainedBean<?> createBean(String name, Class<?> beanType, BeanContainer.LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer)
getBeanback to summary
public <B> ContainedBean<B> getBean(Class<B> beanType, BeanContainer.LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer)

Implements org.hibernate.resource.beans.container.spi.BeanContainer.getBean.

Annotations
@Override
@SuppressWarnings:unchecked
getBeanback to summary
public <B> ContainedBean<B> getBean(String name, Class<B> beanType, BeanContainer.LifecycleOptions lifecycleOptions, BeanInstanceProducer fallbackProducer)

Implements org.hibernate.resource.beans.container.spi.BeanContainer.getBean.

Annotations
@Override
@SuppressWarnings:unchecked
stopback to summary
public void stop()

Implements org.hibernate.service.spi.Stoppable.stop.

Doc from org.hibernate.service.spi.Stoppable.stop.

Stop phase notification

Annotations
@Override
org.springframework.orm.hibernate5 back to summary

private final Class SpringBeanContainer.SpringContainedBean<B>

extends Object
implements ContainedBean<B>
Class Inheritance
  • java.lang.Object
  • org.springframework.orm.hibernate5.SpringBeanContainer.SpringContainedBean
All Implemented Interfaces
org.hibernate.resource.beans.container.spi.ContainedBean

Field Summary

Modifier and TypeField and Description
private final B
private Consumer<B>

Constructor Summary

AccessConstructor and Description
public
SpringContainedBean(B beanInstance)

public
SpringContainedBean(B beanInstance, Consumer<B> destructionCallback)

Method Summary

Modifier and TypeMethod and Description
public void
public B
getBeanInstance()

Implements org.hibernate.resource.beans.container.spi.ContainedBean.getBeanInstance.

Get the bean instance producer associated with this container-backed bean

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanInstanceback to summary
private final B beanInstance
destructionCallbackback to summary
private Consumer<B> destructionCallback
Annotations
@Nullable

Constructor Detail

SpringContainedBeanback to summary
public SpringContainedBean(B beanInstance)
SpringContainedBeanback to summary
public SpringContainedBean(B beanInstance, Consumer<B> destructionCallback)

Method Detail

destroyIfNecessaryback to summary
public void destroyIfNecessary()
getBeanInstanceback to summary
public B getBeanInstance()

Implements org.hibernate.resource.beans.container.spi.ContainedBean.getBeanInstance.

Doc from org.hibernate.resource.beans.container.spi.ContainedBean.getBeanInstance.

Get the bean instance producer associated with this container-backed bean

Annotations
@Override