From 9d685a2c47820a04ea71b58a1887a6de4ea80101 Mon Sep 17 00:00:00 2001 From: Hynek Mlnarik Date: Fri, 27 Sep 2019 08:48:45 +0200 Subject: [PATCH] KEYCLOAK-11558 Fix unique constraint violation in PartialImportTest (cherry picked from commit 672703cbc1320466d37761c4cb0d46c5dd0ce0f1) --- .../java/org/keycloak/models/jpa/JpaRealmProvider.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java index f749203aff..8c5f15c5c9 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java @@ -40,7 +40,6 @@ import org.keycloak.models.jpa.entities.RoleEntity; import org.keycloak.models.utils.KeycloakModelUtils; import javax.persistence.EntityManager; -import javax.persistence.FlushModeType; import javax.persistence.TypedQuery; import java.util.*; import java.util.stream.Collectors; @@ -499,11 +498,7 @@ public class JpaRealmProvider implements RealmProvider { RealmEntity realmEntity = em.getReference(RealmEntity.class, realm.getId()); groupEntity.setRealm(realmEntity); em.persist(groupEntity); - // KEYCLOAK-8253 - Skip / postpone the EM flush if there's an active WIP transaction and EM flush mode is set to AUTO (the default) - // This improves the time performance of LDAP groups sync and EM flush in that case is performed anyway as part of the TX commit - if (!session.getTransactionManager().isActive() || em.getFlushMode() != FlushModeType.AUTO) { - em.flush(); - } + em.flush(); realmEntity.getGroups().add(groupEntity); GroupAdapter adapter = new GroupAdapter(realm, em, groupEntity);