This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch v4
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/v4 by this push:
     new 3b19a0d2ee7 CAUSEWAY-3895: temporary workaround for Spring's 
DefaultJpaContext may throw '... managed by more than one EntityManagers'
3b19a0d2ee7 is described below

commit 3b19a0d2ee724718b69c172a7275fba596fa682b
Author: Andi Huber <[email protected]>
AuthorDate: Wed Jun 25 12:48:44 2025 +0200

    CAUSEWAY-3895: temporary workaround for Spring's DefaultJpaContext may
    throw '... managed by more than one EntityManagers'
---
 .../CausewayModulePersistenceJpaIntegration.java        | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git 
a/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
 
b/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
index 17515670dd7..12e728d3596 100644
--- 
a/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
+++ 
b/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
@@ -18,10 +18,16 @@
  */
 package org.apache.causeway.persistence.jpa.integration;
 
+import java.util.Set;
+
+import jakarta.persistence.EntityManager;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
-
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.jpa.repository.JpaContext;
+import org.springframework.data.jpa.repository.support.DefaultJpaContext;
 import org.apache.causeway.core.runtime.CausewayModuleCoreRuntime;
 import 
org.apache.causeway.persistence.commons.CausewayModulePersistenceCommons;
 import 
org.apache.causeway.persistence.jpa.integration.entity.JpaEntityIntegration;
@@ -43,7 +49,7 @@
 import 
org.apache.causeway.persistence.jpa.integration.typeconverters.schema.v2.CausewayOidDtoConverter;
 import 
org.apache.causeway.persistence.jpa.metamodel.CausewayModulePersistenceJpaMetamodel;
 
-@Configuration
+@Configuration(proxyBeanMethods = false)
 @Import({
         // modules
         CausewayModuleCoreRuntime.class,
@@ -79,4 +85,11 @@
 })
 public class CausewayModulePersistenceJpaIntegration {
 
+    //TODO close issue https://issues.apache.org/jira/browse/CAUSEWAY-3895 
once this can be removed
+    @Bean @Primary
+    public JpaContext defaultJpaContextWorkaround(Set<EntityManager> 
entityManagers) {
+        var setOfOne = Set.of(entityManagers.iterator().next());
+        return new DefaultJpaContext(setOfOne);
+    }
+
 }

Reply via email to