BeforeBeanDiscovery.addQualifier() question
ljnelson Aug 1, 2018 3:19 PMI'm doing awful things with JPA and CDI. :-)
One experiment that I am working on starts like this:
private final void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) {
if (event != null) {
event.addQualifier(PersistenceContext.class); // don't judge :-)
}
}
private final void processAnnotatedType(@Observes @WithAnnotations(PersistenceContext.class) final ProcessAnnotatedType<?> event) {
if (event != null) {
event.configureAnnotatedType()
.filterFields(af -> af.getAnnotation(PersistenceContext.class) != null && af.getAnnotation(Inject.class) == null)
.forEach(afc -> afc.add(InjectLiteral.INSTANCE)); // don't judge :-)
}
}
I don't want to talk about whether this is a good idea (it almost certainly is not :-)).
When my extension runs, I can see that both of these methods fire. That's good.
But then Weld says that PersistenceContext is not a qualifier:
org.jboss.weld.exceptions.IllegalArgumentException: WELD-001301: Annotation QualifierInstance {annotationClass=interface javax.persistence.PersistenceContext, values={name=, synchronization=SYNCHRONIZED, type=TRANSACTION, unitName=test, properties=[Ljavax.persistence.PersistenceProperty;@3ad017e8}} is not a qualifier
at org.jboss.weld.resolution.ResolvableBuilder.checkQualifier(ResolvableBuilder.java:221)
at org.jboss.weld.resolution.ResolvableBuilder.addQualifier(ResolvableBuilder.java:188)
at org.jboss.weld.resolution.ResolvableBuilder.addQualifiers(ResolvableBuilder.java:214)
at org.jboss.weld.resolution.ResolvableBuilder.<init>(ResolvableBuilder.java:90)
at org.jboss.weld.manager.BeanManagerImpl.getBeans(BeanManagerImpl.java:517)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:376)
I thought the whole point of BeforeBeanDiscovery#addQualifier(Class<? extends Annotation>) was to make a non-Qualifier-annotated annotation (like PersistenceContext) indistinguishable (to Weld) from a Qualifier-annotated annotation? Is this a bug (I doubt it) or have I misunderstood something?
(I should add that I'm well aware that I can do custom injection using ProcessInjectionTarget events but I'm curious why the above doesn't work.)
Best,
Laird