FISH-8309: Persistence Context is NULL on CDI Injected beans into MDB and tck fix #6744
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for Persistence Context injection issue on CDI beans and TCK fix for EJB Remote tests
Description
This PR addresses an issue where a PersistenceContext injected into a CDI bean, subsequently injected into a Message-Driven Bean (MDB) or a Stateless EJB, resolves to null. The problem occurs due to the different contexts in which the EntityManager Resource Descriptor instances are added during processing.
Context
The issue arises when the EntityManager Resource Descriptor instance added to the CDI bean's EjbBundleDescriptor is not accessed from the MDB bean's EjbMessageBeanDescriptor. Although EjbBundleDescriptor is the parent descriptor context, it is not the superclass of EjbMessageBeanDescriptor. As a result, when accessing the EntityManager Resource Descriptor from EjbMessageBeanDescriptor, it does not look up in the EjbBundleDescriptor context, leading to a null resolution of the PersistenceContext.
An instance of a PersistenceContext injected into a CDI bean that is then injected into a Message-Driven bean, incorrectly resolves to NULL.
The injection of a
@PersistenceContext
should work in this case, as the injection of CDI beans is fully supported in Message Driven Beans.Testing
Steps to Reproduce
1 - Download the attached project and build it.
3598-payara-jms-inject-bug-reproducerPayara6.zip
mvn clean install
2 - Start a new Payara Server domain (the default domain works well)
asadmin start-domain domain1
3 - Create a new JMS Topic with the following command:
asadmin create-jms-resource --resType=jakarta.jms.Topic --property=Name=DemoTopic jms/PayaraDemoJmsTopic
4 - Deploy the EAR artefact from the project build in the server’s DAS:
asadmin deploy payara-jms-inject-bug-reproducer-ear/target/payara-jms-inject-bug-reproducer-ear-0.0.1-SNAPSHOT.ear
5 - Fire this sample HTTP request:
curl -H "Content-Type: text/plain" -X POST http://localhost:8080/payara-bug-jms/api/data/createJms -d "This is a sample message"
The request will be completed successfully, but the following error stack trace (and additional details) will be printed out to the server log:
Expected Outcome
An instance of a
PersistenceContext
should not be null when injected on a CDI bean that is injected into an MDB. The reproducer code tests the injection of a persistence context directly in the Message Driven Bean and on the CDI bean when used directly by an HTTP resource.The same scenario tested on Payara Server 6 fails with the same error.
You can test the reproducer on Payara Server 6 using the same application, but you’ll have to modify the Message Driven Bean configuration to reference a jakarta.jms.Topic instead:
Use this same principle for creating the topic on the server.
Solution
To resolve this issue, the EntityManager Resource Descriptor instance added to the CDI bean's
EjbBundleDescriptor
context should also be accessible from the MDB bean'sEjbMessageBeanDescriptor
context. This can be achieved by ensuring that processing is done in a way thatEntityManager
Resource Descriptors are looked up from child contexts to parent context.Blockers
Testing
New tests
Testing Performed
Manual testing following steps to reproduce and seeing the following messages on console:
and passing EJB TCK from CDI
[INFO] Tests run: 9, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.974 s - in TestSuite [INFO] [INFO] Results: [INFO] [INFO] Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
and the full execution:
[INFO] [mvn.test] [INFO] Tests run: 1831, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 960.949 s - in TestSuite [INFO] [mvn.test] [INFO] [INFO] [mvn.test] [INFO] Results: [INFO] [mvn.test] [INFO] [INFO] [mvn.test] [INFO] Tests run: 1831, Failures: 0, Errors: 0, Skipped: 0 [INFO] [mvn.test] [INFO] [INFO] [mvn.test] [INFO] [INFO] [mvn.test] [INFO] --- maven-surefire-report-plugin:3.0.0-M5:report-only (generate-test-report) @ weld-payara-runner-tck --- [INFO] [mvn.test] [WARNING] Unable to locate Test Source XRef to link to - DISABLED
Testing Environment
windows 11, Azul JDK 11, Maven 3.9.5
Ubuntu Linux 20.04, Azul JDK 11, Maven 3.8.6
Documentation
Notes for Reviewers