diff --git a/boms/tomee-microprofile/pom.xml b/boms/tomee-microprofile/pom.xml
index c2b83d3892b..414ea3ac071 100644
--- a/boms/tomee-microprofile/pom.xml
+++ b/boms/tomee-microprofile/pom.xml
@@ -554,7 +554,7 @@
org.apache.openjpa
openjpa
- 4.1.1
+ 4.2.0
org.apache.openwebbeans
diff --git a/boms/tomee-plume/pom.xml b/boms/tomee-plume/pom.xml
index d6f4ae6e35a..d97e51fd8ef 100644
--- a/boms/tomee-plume/pom.xml
+++ b/boms/tomee-plume/pom.xml
@@ -589,7 +589,7 @@
org.apache.openjpa
openjpa
- 4.1.1
+ 4.2.0
org.apache.openwebbeans
diff --git a/boms/tomee-plus/pom.xml b/boms/tomee-plus/pom.xml
index be573f88500..0a5ea6b4cf0 100644
--- a/boms/tomee-plus/pom.xml
+++ b/boms/tomee-plus/pom.xml
@@ -599,7 +599,7 @@
org.apache.openjpa
openjpa
- 4.1.1
+ 4.2.0
org.apache.openwebbeans
diff --git a/boms/tomee-webprofile/pom.xml b/boms/tomee-webprofile/pom.xml
index f81dfbbb62e..d25d9f2c0d2 100644
--- a/boms/tomee-webprofile/pom.xml
+++ b/boms/tomee-webprofile/pom.xml
@@ -279,7 +279,7 @@
org.apache.openjpa
openjpa
- 4.1.1
+ 4.2.0
org.apache.openwebbeans
diff --git a/container/openejb-jakarta-data/src/main/java/org/apache/openejb/data/handler/RepositoryInvocationHandler.java b/container/openejb-jakarta-data/src/main/java/org/apache/openejb/data/handler/RepositoryInvocationHandler.java
index 581e8a87ee7..d969813b9c5 100644
--- a/container/openejb-jakarta-data/src/main/java/org/apache/openejb/data/handler/RepositoryInvocationHandler.java
+++ b/container/openejb-jakarta-data/src/main/java/org/apache/openejb/data/handler/RepositoryInvocationHandler.java
@@ -332,12 +332,8 @@ private T handleUpdate(final EntityManager em, final Object[] args) {
}
/**
- * Performs an update with version checking. The strategy depends on the JPA provider:
- *
- * - Hibernate/EclipseLink: standard {@code em.merge()} handles @Version correctly
- * - OpenJPA: requires a workaround — reflection-based field copying with
- * OPTIMISTIC_FORCE_INCREMENT because OpenJPA restricts setting @Version fields
- *
+ * Performs an update with version checking: verifies the entity exists and its
+ * {@code @Version} matches before delegating to {@code em.merge()}.
*/
private Object mergeWithVersionCheck(final EntityManager em, final Object entity) {
final Object id = getEntityId(em, entity);
@@ -351,57 +347,8 @@ private Object mergeWithVersionCheck(final EntityManager em, final Object entity
"Entity not found for update: " + entity);
}
- // Check version before merge
checkVersionMatch(em, entity, existing);
-
- // Providers other than OpenJPA handle @Version correctly via em.merge()
- if (!isOpenJpa(em)) {
- return em.merge(entity);
- }
-
- // OpenJPA workaround: copy fields via reflection, force version increment
- try {
- final jakarta.persistence.metamodel.EntityType> entityType =
- em.getMetamodel().entity(entity.getClass());
-
- for (final jakarta.persistence.metamodel.Attribute, ?> attr : entityType.getAttributes()) {
- if (attr instanceof jakarta.persistence.metamodel.SingularAttribute, ?> sa) {
- if (sa.isId() || sa.isVersion()) {
- continue;
- }
- }
- final java.lang.reflect.Field field = findField(entity.getClass(), attr.getName());
- field.setAccessible(true);
- final java.lang.reflect.Field existingField = findField(existing.getClass(), attr.getName());
- existingField.setAccessible(true);
- existingField.set(existing, field.get(entity));
- }
- em.lock(existing, jakarta.persistence.LockModeType.OPTIMISTIC_FORCE_INCREMENT);
- em.flush();
- em.refresh(existing);
- // Copy updated fields (including version) back to the input entity
- for (final jakarta.persistence.metamodel.Attribute, ?> attr : entityType.getAttributes()) {
- try {
- final java.lang.reflect.Field f = findField(entity.getClass(), attr.getName());
- f.setAccessible(true);
- final java.lang.reflect.Field ef = findField(existing.getClass(), attr.getName());
- ef.setAccessible(true);
- f.set(entity, ef.get(existing));
- } catch (final NoSuchFieldException ignored) {
- // skip
- }
- }
- return entity;
- } catch (final jakarta.data.exceptions.OptimisticLockingFailureException e) {
- throw e;
- } catch (final Exception e) {
- return em.merge(entity);
- }
- }
-
- private static boolean isOpenJpa(final EntityManager em) {
- return em.getClass().getName().startsWith("org.apache.openjpa.")
- || em.getDelegate().getClass().getName().startsWith("org.apache.openjpa.");
+ return em.merge(entity);
}
private Object handleFindById(final EntityManager em, final Method method, final Object[] args) {
@@ -640,18 +587,6 @@ private void removeEntity(final EntityManager em, final Object entity) {
}
}
- private static java.lang.reflect.Field findField(final Class> clazz, final String name) throws NoSuchFieldException {
- Class> current = clazz;
- while (current != null) {
- try {
- return current.getDeclaredField(name);
- } catch (final NoSuchFieldException e) {
- current = current.getSuperclass();
- }
- }
- throw new NoSuchFieldException(name);
- }
-
/**
* Checks if a deleteById method is a custom one declared on the repository (with @By annotations
* pointing to real fields) vs the inherited CrudRepository.deleteById (which may have synthetic @By).
diff --git a/pom.xml b/pom.xml
index 37b56862b13..082cd6daa68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -217,7 +217,7 @@
1.1.1
2.2.0
4.1.4
- 4.1.1
+ 4.2.0
4.1.1
5.0.2