私の英語で申し訳ありませんが、@EntityManagerConfigで@Respositoryを使用しようとしているときに、cdi 1.0、deltaspike 0.5、およびprimefaces 4.0を使用した戦争プロジェクトがあります。異なる@Qualifiersを持つentityManagerの2つのプロデュースがあるため、使用していますアプリケーションサーバー用のglassfish 4これは、リポジトリ、プロデュース、およびEntityManagerResolverのコードです。
リポジトリ:
@Repository(forEntity = User.class)
@EntityManagerConfig(entityManagerResolver = HbsWebEntityManagerResolver.class, flushMode = FlushModeType.AUTO)
public abstract class UserRepository extends
AbstractEntityRepository<User, Integer> {
@Query(named = User.BY_LOGIN)
public abstract User findByLoginEqual(@QueryParam("login") String login);
}
EntityManagerResolver:
public class HbsWebEntityManagerResolver implements EntityManagerResolver{
@Inject
@HbsWeb
private EntityManager hbsWebEntityManager;
@Override
public EntityManager resolveEntityManager() {
return hbsWebEntityManager;
}
}
プロデュース:
@ApplicationScoped
public class EntityManagerProducer {
@PersistenceUnit(unitName="HBS")
private EntityManagerFactory hbsEntityManager;
@PersistenceUnit(unitName="HBSWEB")
private EntityManagerFactory hbsWebEntityManager;
@Produces
@Hbs
protected EntityManager createHbsEntityManager() {
return hbsEntityManager.createEntityManager();
}
protected void closeHbsEntityManager(
@Disposes @Hbs EntityManager entityManager) {
if (entityManager.isOpen()) {
entityManager.close();
}
}
@Produces
@HbsWeb
protected EntityManager createHbsWebEntityManager() {
return hbsWebEntityManager.createEntityManager();
}
protected void closeHbsWebEntityManager(
@Disposes @HbsWeb EntityManager entityManager) {
if (entityManager.isOpen()) {
entityManager.close();
}
}
}
@inject でリポジトリを使用しようとすると、次のエラーが発生します。
org.apache.deltaspike.data.impl.handler.QueryInvocationException: Exception calling Repository: [Repository=class co.com.compuhelmac.hbs.repository.UserRepository_$$_javassist_0,method=findByLoginEqual],exception=class org.jboss.weld.exceptions.AmbiguousResolutionException,message=WELD-001318 Cannot resolve an ambiguous dependency between [Producer Method [EntityManager] with qualifiers [@Hbs @Any] declared as [[BackedAnnotatedMethod] @Produces @Hbs protected co.com.compuhelmac.hbs.database.EntityManagerProducer.createHbsEntityManager()], Producer Method [EntityManager] with qualifiers [@HbsWeb @Any] declared as [[BackedAnnotatedMethod] @Produces @HbsWeb protected co.com.compuhelmac.hbs.database.EntityManagerProducer.createHbsWebEntityManager()]]
at org.apache.deltaspike.data.impl.handler.QueryHandler.invoke(QueryHandler.java:86)
at org.apache.deltaspike.partialbean.impl.PartialBeanAbstractMethodHandler.invoke(PartialBeanAbstractMethodHandler.java:44)
at org.apache.deltaspike.partialbean.impl.MethodHandlerProxy.invoke(MethodHandlerProxy.java:35)
at com.sun.proxy.$Proxy549.invoke(Unknown Source)
at co.com.compuhelmac.hbs.repository.UserRepository_$$_javassist_0.findByLoginEqual(UserRepository_$$_javassist_0.java)
at co.com.compuhelmac.hbs.security.HbsLoginEJB.login(HbsLoginEJB.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [Producer Method [EntityManager] with qualifiers [@Hbs @Any] declared as [[BackedAnnotatedMethod] @Produces @Hbs protected co.com.compuhelmac.hbs.database.EntityManagerProducer.createHbsEntityManager()], Producer Method [EntityManager] with qualifiers [@HbsWeb @Any] declared as [[BackedAnnotatedMethod] @Produces @HbsWeb protected co.com.compuhelmac.hbs.database.EntityManagerProducer.createHbsWebEntityManager()]]
at org.jboss.weld.manager.BeanManagerImpl.resolve(BeanManagerImpl.java:1154)
at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:798)
at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:79)
at org.apache.deltaspike.data.impl.handler.EntityManagerLookup.lookupFor(EntityManagerLookup.java:51)
at org.apache.deltaspike.data.impl.handler.QueryHandler.createContext(QueryHandler.java:97)
at org.apache.deltaspike.data.impl.handler.QueryHandler.invoke(QueryHandler.java:74)
このエラーが発生する理由を知っている人はいますか?