This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 49bbb6872c0 Work around camel-jpa Jakarta Persistence 4 binary
incompatibilities
49bbb6872c0 is described below
commit 49bbb6872c08cce65f595b8550f503632517ad47
Author: James Netherton <[email protected]>
AuthorDate: Mon Nov 16 13:26:20 2026 +0000
Work around camel-jpa Jakarta Persistence 4 binary incompatibilities
camel-jpa is compiled against Jakarta Persistence 3.2. Some
EntityManagerFactory
and EntityManager method descriptors it links to no longer exist in Jakarta
Persistence 4. Rewrite those method calls at build time so that camel-jpa
works
until it is compiled against Jakarta Persistence 4.
Re-enable the jpa integration tests.
Relates to #9357
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../component/jpa/deployment/JpaProcessor.java | 72 ++++++++++++++++++++++
integration-tests/jpa/pom.xml | 3 -
.../camel/quarkus/component/jpa/it/JpaIT.java | 2 -
.../camel/quarkus/component/jpa/it/JpaTest.java | 2 -
.../quarkus/component/jpa/it/NamedJpaTest.java | 2 -
5 files changed, 72 insertions(+), 9 deletions(-)
diff --git
a/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java
b/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java
index 28ddf12ae0d..06bbd0dcefd 100644
---
a/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java
+++
b/extensions/jpa/deployment/src/main/java/org/apache/camel/quarkus/component/jpa/deployment/JpaProcessor.java
@@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.jpa.deployment;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
@@ -46,6 +47,27 @@ import org.objectweb.asm.Opcodes;
class JpaProcessor {
private static final String FEATURE = "camel-jpa";
+ private static final String ENTITY_MANAGER =
"jakarta/persistence/EntityManager";
+ private static final String ENTITY_MANAGER_FACTORY =
"jakarta/persistence/EntityManagerFactory";
+ private static final Map<String, String> ENTITY_MANAGER_QUERY_DESCRIPTORS
= Map.of(
+ "createQuery(Ljava/lang/String;)Ljakarta/persistence/Query;",
+ "(Ljava/lang/String;)Ljakarta/persistence/StatementOrTypedQuery;",
+ "createNamedQuery(Ljava/lang/String;)Ljakarta/persistence/Query;",
+ "(Ljava/lang/String;)Ljakarta/persistence/StatementOrTypedQuery;",
+ "createNativeQuery(Ljava/lang/String;)Ljakarta/persistence/Query;",
+ "(Ljava/lang/String;)Ljakarta/persistence/StatementOrTypedQuery;",
+
"createNativeQuery(Ljava/lang/String;Ljava/lang/Class;)Ljakarta/persistence/Query;",
+
"(Ljava/lang/String;Ljava/lang/Class;)Ljakarta/persistence/TypedQuery;");
+ private static final Set<String> JAKARTA_PERSISTENCE_3_CALLERS = Set.of(
+ "org.apache.camel.component.jpa.JpaConsumer",
+ "org.apache.camel.component.jpa.JpaEndpoint",
+ "org.apache.camel.component.jpa.JpaHelper",
+ "org.apache.camel.component.jpa.QueryBuilder$1",
+ "org.apache.camel.component.jpa.QueryBuilder$2",
+ "org.apache.camel.component.jpa.QueryBuilder$3",
+ "org.apache.camel.component.jpa.QueryBuilder$4",
+ "org.apache.camel.processor.idempotent.jpa.JpaMessageIdRepository",
+ "org.apache.camel.processor.keyvalue.jpa.JpaKeyValueRepository");
@BuildStep
FeatureBuildItem feature() {
@@ -168,6 +190,56 @@ class JpaProcessor {
.build();
}
+ // TODO: Remove this when camel-jpa is compiled against Jakarta
Persistence 4
+ // https://github.com/apache/camel-quarkus/issues/9357
+ @BuildStep
+ void
transformJakartaPersistence3MethodCalls(BuildProducer<BytecodeTransformerBuildItem>
transformers) {
+ // camel-jpa is compiled against Jakarta Persistence 3.2. Rewrite
method calls whose
+ // descriptors no longer exist in Jakarta Persistence 4 so that they
link to the new API
+ for (String className : JAKARTA_PERSISTENCE_3_CALLERS) {
+ transformers.produce(new BytecodeTransformerBuildItem.Builder()
+ .setClassToTransform(className)
+ .setCacheable(true)
+ .setVisitorFunction((name, classVisitor) -> new
ClassVisitor(Gizmo.ASM_API_VERSION, classVisitor) {
+ @Override
+ public MethodVisitor visitMethod(int access, String
methodName, String descriptor,
+ String signature, String[] exceptions) {
+ MethodVisitor visitor = super.visitMethod(access,
methodName, descriptor, signature, exceptions);
+ return new MethodVisitor(Gizmo.ASM_API_VERSION,
visitor) {
+ @Override
+ public void visitMethodInsn(int opcode, String
owner, String name, String desc,
+ boolean isInterface) {
+ if (owner.equals(ENTITY_MANAGER_FACTORY)
+ &&
name.equals("createEntityManager")
+ &&
desc.equals("()Ljakarta/persistence/EntityManager;")) {
+ // createEntityManager() ->
createEntityManager(new EntityManager.CreationOption[0])
+ super.visitInsn(Opcodes.ICONST_0);
+ super.visitTypeInsn(Opcodes.ANEWARRAY,
+
"jakarta/persistence/EntityManager$CreationOption");
+ super.visitMethodInsn(opcode, owner,
name,
+
"([Ljakarta/persistence/EntityManager$CreationOption;)Ljakarta/persistence/EntityManager;",
+ isInterface);
+ return;
+ }
+
+ if (owner.equals(ENTITY_MANAGER)) {
+ // Query creation methods now return
subtypes of Query
+ String newDesc =
ENTITY_MANAGER_QUERY_DESCRIPTORS.get(name + desc);
+ if (newDesc != null) {
+ super.visitMethodInsn(opcode,
owner, name, newDesc, isInterface);
+ return;
+ }
+ }
+
+ super.visitMethodInsn(opcode, owner, name,
desc, isInterface);
+ }
+ };
+ }
+ })
+ .build());
+ }
+ }
+
@BuildStep
BytecodeTransformerBuildItem transformJpaComponent() {
return new BytecodeTransformerBuildItem.Builder()
diff --git a/integration-tests/jpa/pom.xml b/integration-tests/jpa/pom.xml
index 40cce8983f8..48cca68c298 100644
--- a/integration-tests/jpa/pom.xml
+++ b/integration-tests/jpa/pom.xml
@@ -32,9 +32,6 @@
<properties>
<cq.sqlJdbcKind>h2</cq.sqlJdbcKind>
- <!-- TODO: Re-enable when camel-jpa is compiled against Jakarta
Persistence 4 - https://github.com/apache/camel-quarkus/issues/9357 -->
- <skipTests>true</skipTests>
- <quarkus.build.skip>true</quarkus.build.skip>
</properties>
<dependencies>
diff --git
a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java
b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java
index 27e4a23affd..924de39a50e 100644
---
a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java
+++
b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaIT.java
@@ -17,9 +17,7 @@
package org.apache.camel.quarkus.component.jpa.it;
import io.quarkus.test.junit.QuarkusIntegrationTest;
-import org.junit.jupiter.api.Disabled;
-@Disabled("https://github.com/apache/camel-quarkus/issues/9357")
@QuarkusIntegrationTest
class JpaIT extends JpaTest {
diff --git
a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
index cefad8ceaa4..4b284ad2b78 100644
---
a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
+++
b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
@@ -17,9 +17,7 @@
package org.apache.camel.quarkus.component.jpa.it;
import io.quarkus.test.junit.QuarkusTest;
-import org.junit.jupiter.api.Disabled;
-@Disabled("https://github.com/apache/camel-quarkus/issues/9357")
@QuarkusTest
public class JpaTest extends JpaTestBase {
}
diff --git
a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/NamedJpaTest.java
b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/NamedJpaTest.java
index 6877d4f0fa9..d793e81e4b5 100644
---
a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/NamedJpaTest.java
+++
b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/NamedJpaTest.java
@@ -18,9 +18,7 @@ package org.apache.camel.quarkus.component.jpa.it;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
-import org.junit.jupiter.api.Disabled;
-@Disabled("https://github.com/apache/camel-quarkus/issues/9357")
@QuarkusTest
@TestProfile(NamedJpaTestProfile.class)
public class NamedJpaTest extends JpaTestBase {