diff --git a/components/camel-jpa/pom.xml b/components/camel-jpa/pom.xml index ec0b1d70b66f3..065a11cc9898b 100644 --- a/components/camel-jpa/pom.xml +++ b/components/camel-jpa/pom.xml @@ -32,7 +32,7 @@ Camel JPA support - -javaagent:${project.basedir}/target/openjpa-${openjpa-version}.jar -Xmx3G + -Xmx3G 240 @@ -94,7 +94,15 @@ h2 ${h2-version} test - + + + + org.hibernate.orm + hibernate-core + ${hibernate-version} + test + org.junit.jupiter junit-jupiter @@ -134,6 +142,11 @@ !hibernate + + + -javaagent:${project.basedir}/target/openjpa-${openjpa-version}.jar -Xmx3G + @@ -231,8 +244,11 @@ copy-resources - generate-test-resources + + process-test-resources + true @@ -247,14 +263,6 @@ - - - org.hibernate.orm - hibernate-core - ${hibernate-version} - test - - full diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntry.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntry.java index 95517fb6d96d9..b55e14c61ad78 100644 --- a/components/camel-jpa/src/main/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntry.java +++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntry.java @@ -24,6 +24,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Lob; import jakarta.persistence.Table; +import jakarta.persistence.Transient; /** * JPA entity representing a single key-value entry in the {@code CAMEL_KEYVALUE} table. @@ -97,6 +98,7 @@ public void setExpiresAt(long expiresAt) { * * @return whether the entry is expired */ + @Transient public boolean isExpired() { return expiresAt > 0 && System.currentTimeMillis() >= expiresAt; } diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntryHibernateMappingTest.java b/components/camel-jpa/src/test/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntryHibernateMappingTest.java new file mode 100644 index 0000000000000..5ddde83b0401c --- /dev/null +++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/keyvalue/jpa/KeyValueEntryHibernateMappingTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.processor.keyvalue.jpa; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +/** + * Verifies in every build (not only with -Dhibernate) that Hibernate can map {@link KeyValueEntry}. The entity is + * shipped in the camel-jpa jar and e.g. Quarkus auto-discovers it from the classpath and always maps it with Hibernate, + * so a mapping problem breaks applications that never use the KeyValueRepository (CAMEL-24604: a derived getter + * without @Transient made Hibernate fail with "Could not locate setter method for property 'expired'"). + *

+ * Uses the native Hibernate bootstrap on purpose: it does not go through jakarta.persistence provider resolution, so + * the rest of the test suite keeps using the provider selected by the active maven profile. + */ +class KeyValueEntryHibernateMappingTest { + + @Test + void hibernateMustBeAbleToMapKeyValueEntry() { + StandardServiceRegistry registry = new StandardServiceRegistryBuilder() + .applySetting("hibernate.connection.driver_class", "org.h2.Driver") + .applySetting("hibernate.connection.url", "jdbc:h2:mem:camel24604") + .build(); + try { + assertDoesNotThrow(() -> new MetadataSources(registry) + .addAnnotatedClass(KeyValueEntry.class) + .buildMetadata() + .buildSessionFactory() + .close(), + "Hibernate should be able to build a SessionFactory for KeyValueEntry"); + } finally { + StandardServiceRegistryBuilder.destroy(registry); + } + } +} diff --git a/components/camel-jpa/src/test/resources/META-INF/persistence.xml b/components/camel-jpa/src/test/resources/META-INF/persistence.xml index 68006958b71a1..b77a38fb5b470 100644 --- a/components/camel-jpa/src/test/resources/META-INF/persistence.xml +++ b/components/camel-jpa/src/test/resources/META-INF/persistence.xml @@ -50,6 +50,7 @@ + org.apache.openjpa.persistence.PersistenceProviderImpl org.apache.camel.examples.MultiSteps org.apache.camel.examples.SendEmail @@ -63,6 +64,7 @@ + org.apache.openjpa.persistence.PersistenceProviderImpl org.apache.camel.examples.SendEmail @@ -80,6 +82,7 @@ + org.apache.openjpa.persistence.PersistenceProviderImpl org.apache.camel.processor.keyvalue.jpa.KeyValueEntry @@ -93,6 +96,7 @@ + org.apache.openjpa.persistence.PersistenceProviderImpl org.apache.camel.processor.idempotent.jpa.MessageProcessed diff --git a/components/camel-jpa/src/test/resources/profiles/hibernate/META-INF/persistence.xml b/components/camel-jpa/src/test/resources/profiles/hibernate/META-INF/persistence.xml index 765e0988daba2..cf73163b0b63e 100644 --- a/components/camel-jpa/src/test/resources/profiles/hibernate/META-INF/persistence.xml +++ b/components/camel-jpa/src/test/resources/profiles/hibernate/META-INF/persistence.xml @@ -79,6 +79,18 @@ + + org.hibernate.jpa.HibernatePersistenceProvider + + org.apache.camel.processor.keyvalue.jpa.KeyValueEntry + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider