rzo1 opened a new pull request, #328: URL: https://github.com/apache/openjpa/pull/328
https://issues.apache.org/jira/browse/OPENJPA-3102 Jakarta Persistence 3.2 (section 9.1) says the container passes its BeanManager to `createContainerEntityManagerFactory` in the map under `jakarta.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 via `CDI.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.manager` was not a known property, so the configuration dropped it with an "unknown property" warning. - `EntityListenerCDIFactory` only had the JNDI and `CDI.current()` lookup. - Once the property is registered, setting it called `equals` and `toString` on 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_MANAGER` is added and `PersistenceProductDerivation` registers it as an `ObjectValue`, like `jakarta.persistence.validation.factory`. `OpenJPAConfiguration` gets `getBeanManagerInstance()` and `setBeanManager(Object)`. The value is kept as a plain `Object`, so the configuration does not depend on the CDI API. - `EntityListenerCDIFactory` uses the passed object if it is set (only checked with `instanceof BeanManager`, nothing is called on it before the first listener is created), and the old JNDI and `CDI.current()` lookup otherwise. It is still loaded by class name, with the fallback to `EntityListenerCachedFactory`. - If a BeanManager was passed but the CDI factory cannot be used (e.g. the object is not a BeanManager), OpenJPA logs a warning with the reason instead of only a trace message. - `ObjectValue.set` and `Value.isDefault` no longer call methods on a newly set object. The results are unchanged. - CDI injection for listeners is still only used with `openjpa.EntityListenerFactory=cdi`; applications that do not set it, or do not pass the property, behave as before. - The manual's CDI section documents the property and the fallback. 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 for `jakarta.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. Draft: the TCK and the database builds run on this branch first. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
