From 61fbb2fb2eaa14006b761392d2e1cdd924ee62ea Mon Sep 17 00:00:00 2001 From: vramik Date: Thu, 13 Jan 2022 10:30:43 +0100 Subject: [PATCH] JPA-Map storage might loose writes due to missing locking mechanism Closes #9411 --- .../map/storage/jpa/client/entity/JpaClientEntity.java | 10 ++++++++++ .../META-INF/clients/jpa-clients-changelog-1.xml | 3 +++ 2 files changed, 13 insertions(+) diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientEntity.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientEntity.java index 3d9d7983f9..f9ac39b405 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientEntity.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientEntity.java @@ -36,6 +36,7 @@ import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; +import javax.persistence.Version; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; @@ -54,6 +55,11 @@ public class JpaClientEntity extends AbstractClientEntity implements Serializabl @Column private UUID id; + //used for implicit optimistic locking + @Version + @Column + private int version; + @Type(type = "jsonb") @Column(columnDefinition = "jsonb") private final JpaClientMetadata metadata; @@ -131,6 +137,10 @@ public class JpaClientEntity extends AbstractClientEntity implements Serializabl metadata.setEntityVersion(entityVersion); } + public int getVersion() { + return version; + } + @Override public String getId() { return id == null ? null : id.toString(); diff --git a/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml b/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml index f5da9e35e2..4a48fe088b 100644 --- a/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml +++ b/model/map-jpa/src/main/resources/META-INF/clients/jpa-clients-changelog-1.xml @@ -29,6 +29,9 @@ limitations under the License. + + +