rzo1 opened a new pull request, #322: URL: https://github.com/apache/openjpa/pull/322
https://issues.apache.org/jira/browse/OPENJPA-3097 Since 4.2.0, creating an EntityManagerFactory fails when an entity class is already loaded unenhanced and runtime enhancement redefines it: ``` PersistenceException: class redefinition failed: attempted to change superclass or interfaces at org.apache.openjpa.enhance.ClassRedefiner.redefineClasses(ClassRedefiner.java:73) at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(...) ``` 4.1.1 worked. Seen in several TomEE examples, where the container registers the persistence unit's ClassTransformer and the entity class is loaded before the persistence unit enhances it. Cause: 4.2.0 changed `ClassRedefiner` from `Instrumentation.retransformClasses` with a temporary transformer to `Instrumentation.redefineClasses`, with a comment saying this bypasses registered transformers. The JVM does the opposite: `redefineClasses` passes the new bytes to every registered transformer, including ones registered without retransform support, while a retransformation only calls the retransform-capable ones. A `PCClassFileTransformer` registered by the agent or a container therefore enhanced the prepared bytes again and added `PersistenceCapable`, which the JVM rejects for a loaded class. Fix: go back to `retransformClasses` with a temporary transformer that returns the prepared bytes, and remove it afterwards. The 4.2.0 error handling stays: a schema change is still reported as an error, and other failures such as `VerifyError` still fall back to subclass enhancement. A schema change is not turned into a fallback on purpose: if the loaded class cannot be redefined, field changes made through the entity class are not tracked, so updates would be lost without an error (checked with JaCoCo adding members at first load). The 4.2 migration note is updated. Tests (Derby): new `TestRedefineLoadedUnenhancedClass` starts a child JVM with self-attach, loads the entity before the EMF is created (`RuntimeUnenhancedClasses=supported`), registers the persistence unit's transformer the way a container does, then persists and updates the entity and checks that the update is stored. It fails on master with the reported exception and runs in the regular build. openjpa-lib, openjpa-kernel, openjpa-persistence, the runtime enhancement tests in openjpa-persistence-jdbc and the test-dynamic-enhancer suite pass. Draft: the TCK runs on this branch first, since this path was changed for the OPENJPA-2940 TCK work. -- 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]
