diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/delegate/JpaClientScopeDelegateProvider.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/delegate/JpaClientScopeDelegateProvider.java index d6d5008d3e..025a9ad70c 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/delegate/JpaClientScopeDelegateProvider.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/delegate/JpaClientScopeDelegateProvider.java @@ -28,47 +28,47 @@ import org.keycloak.models.map.clientscope.MapClientScopeEntity; import org.keycloak.models.map.clientscope.MapClientScopeEntityFields; import org.keycloak.models.map.common.EntityField; import org.keycloak.models.map.common.delegate.DelegateProvider; +import org.keycloak.models.map.storage.jpa.JpaDelegateProvider; import org.keycloak.models.map.storage.jpa.clientscope.entity.JpaClientScopeEntity; -public class JpaClientScopeDelegateProvider implements DelegateProvider { +public class JpaClientScopeDelegateProvider extends JpaDelegateProvider implements DelegateProvider { - private JpaClientScopeEntity delegate; private final EntityManager em; public JpaClientScopeDelegateProvider(JpaClientScopeEntity delegate, EntityManager em) { - this.delegate = delegate; + super(delegate); this.em = em; } @Override public MapClientScopeEntity getDelegate(boolean isRead, Enum> field, Object... parameters) { - if (delegate.isMetadataInitialized()) return delegate; + if (getDelegate().isMetadataInitialized()) return getDelegate(); if (isRead) { if (field instanceof MapClientScopeEntityFields) { switch ((MapClientScopeEntityFields) field) { case ID: case REALM_ID: case NAME: - return delegate; + return getDelegate(); case ATTRIBUTES: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery query = cb.createQuery(JpaClientScopeEntity.class); Root root = query.from(JpaClientScopeEntity.class); root.fetch("attributes", JoinType.INNER); - query.select(root).where(cb.equal(root.get("id"), UUID.fromString(delegate.getId()))); + query.select(root).where(cb.equal(root.get("id"), UUID.fromString(getDelegate().getId()))); - delegate = em.createQuery(query).getSingleResult(); + setDelegate(em.createQuery(query).getSingleResult()); break; default: - delegate = em.find(JpaClientScopeEntity.class, UUID.fromString(delegate.getId())); + setDelegate(em.find(JpaClientScopeEntity.class, UUID.fromString(getDelegate().getId()))); } } else throw new IllegalStateException("Not a valid client scope field: " + field); } else { - delegate = em.find(JpaClientScopeEntity.class, UUID.fromString(delegate.getId())); + setDelegate(em.find(JpaClientScopeEntity.class, UUID.fromString(getDelegate().getId()))); } - return delegate; + return getDelegate(); } } diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/entity/JpaClientScopeEntity.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/entity/JpaClientScopeEntity.java index 9819845f39..6a8dbafb4b 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/entity/JpaClientScopeEntity.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientscope/entity/JpaClientScopeEntity.java @@ -135,6 +135,7 @@ public class JpaClientScopeEntity extends AbstractClientScopeEntity implements J metadata.setEntityVersion(entityVersion); } + @Override public int getVersion() { return version; }