Change the flush mode to auto and fixing how entities are checked if they are loaded in the EM

Closes #10411
This commit is contained in:
Pedro Igor 2022-03-07 13:27:01 -03:00
parent f06ba05405
commit ad865e75c1
2 changed files with 4 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}