public final class SpringBeanContainer extends java.lang.Object implements org.hibernate.resource.beans.container.spi.BeanContainer
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: In particular with Hibernate 5.3, the Hibernate SessionFactory
will natively expose the JPA EntityManagerFactory
interface as well, and
Hibernate BeanContainer
integration will be registered out of the box.LocalSessionFactoryBean.setBeanFactory(org.springframework.beans.factory.BeanFactory)
,
LocalSessionFactoryBuilder.setBeanContainer(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
,
AbstractEntityManagerFactoryBean.setJpaPropertyMap(java.util.Map<java.lang.String, ?>)
,
AvailableSettings.BEAN_CONTAINER
org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions
Constructor and Description |
---|
SpringBeanContainer(ConfigurableListableBeanFactory beanFactory)
Instantiate a new SpringBeanContainer for the given bean factory.
|
Modifier and Type | Method and Description |
---|---|
<B> org.hibernate.resource.beans.container.spi.ContainedBean<B> |
getBean(java.lang.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(java.lang.String name,
java.lang.Class<B> beanType,
org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions,
org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer) |
void |
stop() |
public SpringBeanContainer(ConfigurableListableBeanFactory beanFactory)
beanFactory
- the Spring bean factory to delegate topublic <B> org.hibernate.resource.beans.container.spi.ContainedBean<B> getBean(java.lang.Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
getBean
in interface org.hibernate.resource.beans.container.spi.BeanContainer
public <B> org.hibernate.resource.beans.container.spi.ContainedBean<B> getBean(java.lang.String name, java.lang.Class<B> beanType, org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions lifecycleOptions, org.hibernate.resource.beans.spi.BeanInstanceProducer fallbackProducer)
getBean
in interface org.hibernate.resource.beans.container.spi.BeanContainer