diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java index 9f0768e642..630491ae52 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java @@ -6,10 +6,6 @@ */ package org.hibernate.resource.beans.internal; -import java.util.Set; -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; - /** * @author Steve Ebersole */ @@ -22,24 +18,6 @@ public class Helper { private Helper() { } - @SuppressWarnings("unchecked") - public Bean getNamedBean(String beanName, Class beanContract, BeanManager beanManager) { - Set> beans = beanManager.getBeans( beanContract, new NamedBeanQualifier( beanName ) ); - - if ( beans.isEmpty() ) { - throw new IllegalArgumentException( - "BeanManager returned no matching beans: name = " + beanName + "; contract = " + beanContract.getName() - ); - } - if ( beans.size() > 1 ) { - throw new IllegalArgumentException( - "BeanManager returned multiple matching beans: name = " + beanName + "; contract = " + beanContract.getName() - ); - } - - return (Bean) beans.iterator().next(); - } - public CdiLifecycleManagementStrategy getLifecycleManagementStrategy(boolean shouldRegistryManageLifecycle) { if ( shouldRegistryManageLifecycle ) { return JpaCdiLifecycleManagementStrategy.INSTANCE; diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/JpaCdiLifecycleManagementStrategy.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/JpaCdiLifecycleManagementStrategy.java index 48268abe90..565a7c0b7f 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/JpaCdiLifecycleManagementStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/JpaCdiLifecycleManagementStrategy.java @@ -6,6 +6,7 @@ */ package org.hibernate.resource.beans.internal; +import java.util.Set; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.Bean; @@ -48,9 +49,11 @@ class JpaCdiLifecycleManagementStrategy implements CdiLifecycleManagementStrateg return new JpaManagedBeanImpl<>( beanClass, injectionTarget, creationalContext, beanInstance ); } + @SuppressWarnings("unchecked") @Override public ManagedBean createBean(BeanManager beanManager, String beanName, Class beanClass) { - Bean bean = Helper.INSTANCE.getNamedBean( beanName, beanClass, beanManager ); + Set> beans = beanManager.getBeans( beanClass, new NamedBeanQualifier( beanName ) ); + Bean bean = (Bean) beanManager.resolve( beans ); CreationalContext creationalContext = beanManager.createCreationalContext( null );