KEYCLOAK-11558 Fix unique constraint violation in PartialImportTest

(cherry picked from commit 672703cbc1320466d37761c4cb0d46c5dd0ce0f1)
This commit is contained in:
Hynek Mlnarik 2019-09-27 08:48:45 +02:00 committed by Hynek Mlnařík
parent f0a506a143
commit 9d685a2c47

View file

@ -40,7 +40,6 @@ import org.keycloak.models.jpa.entities.RoleEntity;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -499,11 +498,7 @@ public class JpaRealmProvider implements RealmProvider {
RealmEntity realmEntity = em.getReference(RealmEntity.class, realm.getId()); RealmEntity realmEntity = em.getReference(RealmEntity.class, realm.getId());
groupEntity.setRealm(realmEntity); groupEntity.setRealm(realmEntity);
em.persist(groupEntity); 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) em.flush();
// 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();
}
realmEntity.getGroups().add(groupEntity); realmEntity.getGroups().add(groupEntity);
GroupAdapter adapter = new GroupAdapter(realm, em, groupEntity); GroupAdapter adapter = new GroupAdapter(realm, em, groupEntity);