First I have 3 producers:
@Produces
public EntityManager produce() {
return EntityManagerProvider.instance("cdipu").em();
}
@Produces
@RiderPU("cdipu2") //just a CDI qualifier with a value attribute, like @Named
public EntityManager produceEm2() {
return EntityManagerProvider.instance("cdipu2").em();
}
@Produces
@RiderPU("cdipu3")
public EntityManager produceEm() {
return EntityManagerProvider.instance("cdipu3").em();
}
Secondly I can Inject the entity manager using the qualifier, it’s working because I see each producer method being called:
@Inject
EntityManager em;
@Inject
@RiderPU("cdipu2")
EntityManager em2;
@Inject
@RiderPU("cdipu3")
EntityManager em3;
The issue is when I try to lookup the entity manager based on the qualifier:
@Inject
private Instance<EntityManager> entityManagerInstance;
public EntityManager getInstance(String puName) {
return entityManagerInstance.select(EntityManager.class, new RiderPUAnnotation(puName){}).get();
}
public class RiderPUAnnotation extends AnnotationLiteral<RiderPU> implements RiderPU {
private final String value;
public RiderPUAnnotation(final String value) {
this.value = value;
}
public String value() {
return value;
}
}
The following error is thrown:
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [javax.persistence.EntityManager] is not found with the qualifiers Qualifiers: [@javax.enterprise.inject.Default(),@com.github.database.rider.cdi.api.RiderPU(value="cdipu2")] for injection into Field Injection Point, field name : entityManagerInstance, Bean Owner : [DataSetProcessor, WebBeansType:MANAGED, Name:null, API Types:[java.lang.Object,com.github.database.rider.cdi.DataSetProcessor], Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any]] at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:65) at org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:120) at com.github.database.rider.cdi.DataSetProcessor.resolveEntityManager(DataSetProcessor.java:71) at com.github.database.rider.cdi.DataSetProcessor.init(DataSetProcessor.java:57) at com.github.database.rider.cdi.DataSetProcessor.process(DataSetProcessor.java:122)
CDI implementation is OpenWebBeans 1.6.2
Same happens with OpenWebBeans 2.0.13: