From ad865e75c14f048e2de6748bab6af6c3b495de33 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Mon, 7 Mar 2022 13:27:01 -0300 Subject: [PATCH] Change the flush mode to auto and fixing how entities are checked if they are loaded in the EM Closes #10411 --- .../src/main/java/org/keycloak/models/jpa/JpaUserProvider.java | 3 +-- .../database/jpa/AbstractJpaConnectionProviderFactory.java | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java index 40916246e7..153848053a 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java @@ -1083,7 +1083,6 @@ public class JpaUserProvider implements UserProvider.Streams, UserCredentialStor private UserEntity userInEntityManagerContext(String id) { UserEntity user = em.getReference(UserEntity.class, id); - boolean isLoaded = em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded(user); - return isLoaded ? user : null; + return em.contains(user) ? user : null; } } diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/jpa/AbstractJpaConnectionProviderFactory.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/jpa/AbstractJpaConnectionProviderFactory.java index 56f71d9ddc..35436ab6b3 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/jpa/AbstractJpaConnectionProviderFactory.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/jpa/AbstractJpaConnectionProviderFactory.java @@ -25,6 +25,7 @@ import javax.enterprise.inject.Instance; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; +import javax.persistence.FlushModeType; import javax.persistence.SynchronizationType; import org.hibernate.internal.SessionFactoryImpl; import org.keycloak.Config; @@ -110,6 +111,8 @@ public abstract class AbstractJpaConnectionProviderFactory implements JpaConnect entityManager = PersistenceExceptionConverter.create(session, emf.createEntityManager()); } + entityManager.setFlushMode(FlushModeType.AUTO); + return entityManager; } }