Repository navigation
Conversation
….manager for CDI entity listeners
rmannibucau
approved these changes
Nov 28, 2026
rzo1
marked this pull request as ready for review
November 28, 2026 17:29
Contributor
|
I have just added this feature to OPENJPA-3101, but didn't opened a PR because I'm refactoring the code to make it simpler. If you may, I'd ask to hold a bit because I'm sending soon the new version there incorporating what I may have missed and you put here. |
rzo1
marked this pull request as draft
November 28, 2026 20:10
Contributor
Author
|
Feel free to close it once the combination is up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
https://issues.apache.org/jira/browse/OPENJPA-3102
Jakarta Persistence 3.2 (section 9.1) says the container passes its BeanManager to
createContainerEntityManagerFactoryin the map underjakarta.persistence.bean.manager, and sections 3.6.1 (entity listeners) and 3.9 (attribute converters) both start with "Obtain a BeanManager instance. (See Section 9.1)". OpenJPA ignored this key: the CDI entity listener factory from OPENJPA-3089 always looked up the BeanManager in JNDI (java:comp/BeanManager,java:comp/env/BeanManager) and then viaCDI.current(). TomEE passes the property (as a lazy proxy, because the EMF is often created before CDI is started for the application).Cause:
jakarta.persistence.bean.managerwas not a known property, so the configuration dropped it with an "unknown property" warning.EntityListenerCDIFactoryonly had the JNDI andCDI.current()lookup.equalsandtoStringon the passed object while the EMF was created (ObjectValue.set,Value.isDefault). On TomEE's lazy proxy each call resolves the real BeanManager, which is too early.Changes:
JPAProperties.BEAN_MANAGERis added andPersistenceProductDerivationregisters it as anObjectValue, likejakarta.persistence.validation.factory.OpenJPAConfigurationgetsgetBeanManagerInstance()andsetBeanManager(Object). The value is kept as a plainObject, so the configuration does not depend on the CDI API.EntityListenerCDIFactoryuses the passed object if it is set (only checked withinstanceof BeanManager, nothing is called on it before the first listener is created), and the old JNDI andCDI.current()lookup otherwise. It is still loaded by class name, with the fallback toEntityListenerCachedFactory.ObjectValue.setandValue.isDefaultno longer call methods on a newly set object. The results are unchanged.openjpa.EntityListenerFactory=cdi; applications that do not set it, or do not pass the property, behave as before.Note: a String value for
jakarta.persistence.bean.manager(e.g. in persistence.xml) now fails EMF creation instead of being ignored, the same as forjakarta.persistence.validation.factory. A string can never be a BeanManager.Tests (Derby): new
TestBeanManagerPropertyCDIEntityListeners(OpenWebBeans@Cdi) passes a proxy BeanManager that forwards to the OWB one and counts calls. It checks that the proxy is not called before the first persist and is then used for injection, that the configuration returns the passed object, that the default stateless factory never calls it, and that an object that is not a BeanManager leads to a warning. It fails without the fix. The existing CDI listener tests cover the lookup without the property. The openjpa-lib, openjpa-kernel and openjpa-persistence suites and the full openjpa-persistence-jdbc suite pass.