diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java index 6fc2960b84..5fa648ed36 100644 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java @@ -188,32 +188,32 @@ public class JpaUserSessionPersisterProvider implements UserSessionPersisterProv userSessionIds.add(entity.getUserSessionId()); } - TypedQuery query2 = em.createNamedQuery("findClientSessionsByUserSessions", PersistentClientSessionEntity.class); - query2.setParameter("userSessionIds", userSessionIds); - query2.setParameter("offline", offlineStr); - List clientSessions = query2.getResultList(); + if (!userSessionIds.isEmpty()) { + TypedQuery query2 = em.createNamedQuery("findClientSessionsByUserSessions", PersistentClientSessionEntity.class); + query2.setParameter("userSessionIds", userSessionIds); + query2.setParameter("offline", offlineStr); + List clientSessions = query2.getResultList(); - // Assume both userSessions and clientSessions ordered by userSessionId - int j=0; - for (UserSessionModel ss : result) { - PersistentUserSessionAdapter userSession = (PersistentUserSessionAdapter) ss; - List currentClientSessions = userSession.getClientSessions(); // This is empty now and we want to fill it + // Assume both userSessions and clientSessions ordered by userSessionId + int j = 0; + for (UserSessionModel ss : result) { + PersistentUserSessionAdapter userSession = (PersistentUserSessionAdapter) ss; + List currentClientSessions = userSession.getClientSessions(); // This is empty now and we want to fill it - boolean next = true; - while (next && j sessions = persister.loadUserSessions(0, 1, true); + Assert.assertEquals(0, sessions.size()); + } + private ClientSessionModel createClientSession(ClientModel client, UserSessionModel userSession, String redirect, String state, Set roles, Set protocolMappers) { ClientSessionModel clientSession = session.sessions().createClientSession(realm, client);