FISH-12307 : Add migration advice for Jakarta Persistence 3.2 EntityManager injection ambiguity (FISH-11759) #39
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.
Summary
This PR adds migration advice to detect and help resolve the EntityManager injection ambiguity issue that occurs when migrating to Jakarta EE 11 (Jakarta Persistence 3.2).
This issue was identified in FISH-11759: Ambiguous EntityManager Injection Error in Payara 7.2025.1.Alpha3 (Works in Alpha2).
Problem Description
In Jakarta EE 11, the CDI specification now provides a default EntityManager producer through
PersistenceExtension. When applications have custom@Producesmethods forEntityManagerwithout a qualifier, this causes a WELD-001409 ambiguous dependency error during deployment because CDI cannot determine which producer to use:This pattern worked in Jakarta EE 10 and earlier but breaks in EE 11.
Changes Made
1. Detection Pattern
src/main/resources/config/jakarta11/mappedPatterns/jakarta-persistence.propertiesjakarta-persistence-interface-persistencecontext-cdi-ambiguous-warn@PersistenceContextannotation that may indicate problematic producer patterns2. Advisory Message
src/main/resources/config/jakarta11/advisorMessages/jakarta-persistence-messages.properties3. Fix Recommendations
src/main/resources/config/jakarta11/advisorFix/jakarta-persistence-fix-messages.properties@Inject EntityManagerdirectly (EE11 supports this natively)@Qualifierannotation to custom producers to make them distinct@PersistenceContextdirectly to injection points instead of using producersTesting & Reproduction
Prerequisites
Reproducing with Example Project
The issue can be reproduced using the example project at:
https://github.com/breakponchito/AdvisorReproducerExamples.git
Example Files in Reproducer
The reproducer includes two example files demonstrating the problematic pattern:
EntityManagerProducer.java- Shows the OLD pattern that causes ambiguity:EventService.java- Shows where the injection fails:Expected Output
When running the advisor on the reproducer project, you should see warnings like:
Related Issues
Impact
@PersistenceContextMigration Path
This advisory helps developers proactively identify and fix potential deployment issues before upgrading to Jakarta EE 11 / Payara 7.2025.1.Alpha3+.