Example usage for org.hibernate.resource.beans.spi BeanInstanceProducer produceBeanInstance

List of usage examples for org.hibernate.resource.beans.spi BeanInstanceProducer produceBeanInstance

Introduction

In this page you can find the example usage for org.hibernate.resource.beans.spi BeanInstanceProducer produceBeanInstance.

Prototype

<B> B produceBeanInstance(String name, Class<B> beanType);

Source Link

Document

Produce a named bean instance

Usage

From source file:org.springframework.orm.hibernate5.SpringBeanContainer.java

License:Apache License

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

    try {/*w w w  .  j a v  a  2s  .  c o  m*/
        if (lifecycleOptions.useJpaCompliantCreation()) {
            Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR,
                    false);
            this.beanFactory.applyBeanPropertyValues(bean, name);
            bean = this.beanFactory.initializeBean(bean, name);
            return new SpringContainedBean<>(bean,
                    beanInstance -> this.beanFactory.destroyBean(name, beanInstance));
        } else {
            return new SpringContainedBean<>(this.beanFactory.getBean(name, beanType));
        }
    } catch (BeansException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Falling back to Hibernate's default producer after bean creation failure for "
                    + beanType + ": " + ex);
        }
        return new SpringContainedBean<>(fallbackProducer.produceBeanInstance(name, beanType));
    }
}