JpaCompliantLifecycleStrategy uses deprecated BeanManager method that's gone in CDI 4.0
Description
Activity

Brian StansberryFebruary 25, 2022 at 1:27 PMEdited
No, 6 is enough. Our CDI 4.0 work is only using 5.3 pending completion of If that takes a while and we’re otherwise ready to merge work with CDI 4 we can just temporarily disable the handful of tests affected by this. We’ll never release again from main with Hibernate 5.3.

Sanne GrinoveroFebruary 25, 2022 at 9:54 AM
I see your experiments are running on Hibernate 5.3 - will you need this backported to 5.3?

Brian StansberryFebruary 18, 2022 at 9:25 PM
Sorry, I realize now my issue description buried the fact that there is a different API that CDI wants used; I updated it and now that I’ve found it I added a link to the relevant bit of the CDI 1.2 spec.

Brian StansberryFebruary 18, 2022 at 9:14 PM
I’m not suggesting not creating an InjectionTarget. It’s just that the API CDI wants used to do that was changed in CDI 1.2, from asking the BeanManager to do it directly, to instead asking the BeanManager for an InjectionTargetFactory, which you then ask for an InjectionTarget. See 11.3.21 of the CDI 1.2 spec ( ), particularly
“Null should be passed to InjectionTargetFactory.createInjectionTarget() to create a noncontextual injection target. The method BeanManager.createInjectionTarget() is deprecated since version 1.1 of Contexts and Dependency Injection.”
As 3.5.1 of the JPA spec notes, an entity listener is a non-contextual object.
Now in CDI that recommended way of doing it has become the required way.
Steve EbersoleFebruary 18, 2022 at 2:56 PM
For now we should not do this unless/until we can get the JPA spec matched up. From the spec (ref 3.5.1 Entity Listeners), steps #3 for CDI integration is:
Create an InjectionTarget instance for the annotated type.
JpaCompliantLifecycleStrategy uses BeanManager.createInjectionTarget(AnnotatedType) which is documented (in text, not annoation or javadoc annotation) as “deprecated from CDI 1.1” and has been removed in CDI 4.0[1]. In CDI 1.2 an alternative API was introduced[4], which is now required. Using the old API leads to a test failure in WildFly Preview when I try and integrate CDI 4 and Weld 5[2].
This leads to a failure in WildFly’s EntityListenerInjectionSupportTestCase[3] when it tries to deploy a test deployment:
{code}
Caused by: java.lang.NoSuchMethodError: 'jakarta.enterprise.inject.spi.InjectionTarget jakarta.enterprise.inject.spi.BeanManager.createInjectionTarget(jakarta.enterprise.inject.spi.AnnotatedType)'
at org.hibernate@5.3.24.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy$BeanImpl.initialize(JpaCompliantLifecycleStrategy.java:116)
at org.hibernate@5.3.24.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl$BeanImpl.initialize(CdiBeanContainerExtendedAccessImpl.java:113)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.hibernate@5.3.24.Final//org.hibernate.resource.beans.container.spi.AbstractCdiBeanContainer.forEachBean(AbstractCdiBeanContainer.java:139)
at org.hibernate@5.3.24.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl.beanManagerInitialized(CdiBeanContainerExtendedAccessImpl.java:74)
at org.hibernate.jipijapa-hibernate5-3@27.0.0.Beta1-SNAPSHOT//org.jboss.as.jpa.hibernate5.HibernateExtendedBeanManager.beanManagerIsAvailableForUse(HibernateExtendedBeanManager.java:69)
at org.hibernate.jipijapa-hibernate5-3@27.0.0.Beta1-SNAPSHOT//org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor.markPersistenceUnitAvailable(HibernatePersistenceProviderAdaptor.java:226)
at org.jboss.as.jpa@27.0.0.Beta1-SNAPSHOT//org.jboss.as.jpa.beanmanager.BeanManagerAfterDeploymentValidation$DeferredCall.markPersistenceUnitAvailable(BeanManagerAfterDeploymentValidation.java:83)
at org.jboss.as.jpa@27.0.0.Beta1-SNAPSHOT//org.jboss.as.jpa.beanmanager.BeanManagerAfterDeploymentValidation.markPersistenceUnitAvailable(BeanManagerAfterDeploymentValidation.java:68)
{code}
Note that my branch is using a bytecode transformed Hibernate 5.3 .24when this happens, but my real interest is 6.0.0.CR1 as we want to move to 6.0, and I see the code is the same there.
Per section 11.3.21 of the CDI 1.2 spec[4] the replacement code seems to be BeanManager.getInjectionTargetFactory(type).createInjectionTarget((Bean)null). That is also what the Weld impl of createInjectionTarget does.
[1]
[2]
[3]
[4]