From 0b68db6ba164943d8470d46fb4de326a19fc9485 Mon Sep 17 00:00:00 2001 From: Romain Manni-Bucau Date: Thu, 1 Oct 2020 09:45:50 +0200 Subject: [PATCH] [OPENJPA-2834] enable to bypass synchronizeMappings when calling getProperties --- .../persistence/EntityManagerFactoryImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java index ff06de691..9242ccdc1 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java @@ -119,7 +119,7 @@ public class EntityManagerFactoryImpl if (emEmptyPropsProperties != null) { props.putAll(emEmptyPropsProperties); } else { - props.putAll(createEntityManager().getProperties()); + props.putAll(doCreateEM(SynchronizationType.SYNCHRONIZED, null, true).getProperties()); } // no need to sync or volatile, worse case concurrent threads create 2 instances // we just want to avoid to do it after some "init" phase @@ -198,6 +198,12 @@ public class EntityManagerFactoryImpl */ @Override public OpenJPAEntityManagerSPI createEntityManager(SynchronizationType synchronizationType, Map props) { + return doCreateEM(synchronizationType, props, false); + } + + private OpenJPAEntityManagerSPI doCreateEM(SynchronizationType synchronizationType, + Map props, + boolean byPassSynchronizeMappings) { if (synchronizationType == null) { throw new NullPointerException("SynchronizationType must not be null"); } @@ -271,7 +277,9 @@ public class EntityManagerFactoryImpl } validateCfNameProps(conf, cfName, cf2Name); - Broker broker = _factory.newBroker(user, pass, managed, retainMode, false, cfName, cf2Name); + Broker broker = byPassSynchronizeMappings ? + conf.newBrokerInstance(user, pass) : + _factory.newBroker(user, pass, managed, retainMode, false, cfName, cf2Name); // add autodetach for close and rollback conditions to the configuration broker.setAutoDetach(AutoDetach.DETACH_CLOSE, true);