diff --git a/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java b/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java index 2f329b7858..3e8695c7df 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java +++ b/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java @@ -156,10 +156,12 @@ public final class KeycloakModelUtils { tx.commit(); } } - } finally { + } catch (RuntimeException re) { if (tx.isActive()) { tx.rollback(); } + throw re; + } finally { session.close(); } } diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java index ca8db44e4c..27f9a2fdaa 100755 --- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java +++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java @@ -15,6 +15,7 @@ import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.services.DefaultKeycloakSessionFactory; import org.keycloak.services.managers.ApplianceBootstrap; import org.keycloak.services.managers.BruteForceProtector; +import org.keycloak.services.managers.PeriodicSyncManager; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.TokenManager; import org.keycloak.services.resources.admin.AdminRoot; @@ -148,6 +149,7 @@ public class KeycloakApplication extends Application { TimerProvider timer = sessionFactory.create().getProvider(TimerProvider.class); timer.schedule(new ScheduledTaskRunner(sessionFactory, new ClearExpiredAuditEvents()), interval, "ClearExpiredAuditEvents"); timer.schedule(new ScheduledTaskRunner(sessionFactory, new ClearExpiredUserSessions()), interval, "ClearExpiredUserSessions"); + new PeriodicSyncManager().bootstrap(sessionFactory, timer); } public KeycloakSessionFactory getSessionFactory() {