diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionEntity.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionEntity.java index f34f7a9ce3..0401089220 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionEntity.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionEntity.java @@ -37,6 +37,7 @@ import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.UpdatableEntity; import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_AUTH_SESSION; import org.keycloak.models.map.storage.jpa.JpaRootEntity; +import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity; import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType; import org.keycloak.sessions.CommonClientSessionModel; @@ -52,13 +53,18 @@ import org.keycloak.sessions.CommonClientSessionModel; @Entity @Table(name = "kc_auth_session") @TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)}) -public class JpaAuthenticationSessionEntity extends UpdatableEntity.Impl implements MapAuthenticationSessionEntity, JpaRootEntity { +public class JpaAuthenticationSessionEntity extends UpdatableEntity.Impl implements MapAuthenticationSessionEntity, JpaRootVersionedEntity { @Id @Column @GeneratedValue private UUID id; + //used for implicit optimistic locking + @Version + @Column + private int version; + @Type(type = "jsonb") @Column(columnDefinition = "jsonb") private final JpaAuthenticationSessionMetadata metadata; @@ -107,6 +113,11 @@ public class JpaAuthenticationSessionEntity extends UpdatableEntity.Impl impleme return CURRENT_SCHEMA_VERSION_AUTH_SESSION; } + @Override + public int getVersion() { + return version; + } + @Override public String getTabId() { return metadata.getTabId(); diff --git a/model/map-jpa/src/main/resources/META-INF/auth-sessions/jpa-auth-sessions-changelog-1.xml b/model/map-jpa/src/main/resources/META-INF/auth-sessions/jpa-auth-sessions-changelog-1.xml index 916778faf0..cb8965c07b 100644 --- a/model/map-jpa/src/main/resources/META-INF/auth-sessions/jpa-auth-sessions-changelog-1.xml +++ b/model/map-jpa/src/main/resources/META-INF/auth-sessions/jpa-auth-sessions-changelog-1.xml @@ -51,6 +51,9 @@ limitations under the License. + + +