Set correct entity version when adding a child entity with its own entity versioning

Closes #14273
This commit is contained in:
vramik 2022-09-08 11:36:44 +02:00 committed by Hynek Mlnařík
parent 84576ffc0e
commit fb33cbc2bd
4 changed files with 9 additions and 9 deletions

View file

@ -200,7 +200,7 @@ public class JpaRootAuthenticationSessionEntity extends AbstractRootAuthenticati
public void addAuthenticationSession(MapAuthenticationSessionEntity authenticationSession) {
JpaAuthenticationSessionEntity jpaAuthSession = JpaAuthenticationSessionEntity.class.cast(CLONER.from(authenticationSession));
jpaAuthSession.setParent(this);
jpaAuthSession.setEntityVersion(this.getEntityVersion());
jpaAuthSession.setEntityVersion(Constants.CURRENT_SCHEMA_VERSION_AUTH_SESSION);
authSessions.add(jpaAuthSession);
}

View file

@ -55,10 +55,10 @@ import org.keycloak.models.map.realm.entity.MapOTPPolicyEntity;
import org.keycloak.models.map.realm.entity.MapRequiredActionProviderEntity;
import org.keycloak.models.map.realm.entity.MapRequiredCredentialEntity;
import org.keycloak.models.map.realm.entity.MapWebAuthnPolicyEntity;
import org.keycloak.models.map.storage.jpa.Constants;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_REALM;
import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.CLONER;
/**
@ -161,7 +161,7 @@ public class JpaRealmEntity extends MapRealmEntity.AbstractRealmEntity implement
@Override
public Integer getCurrentSchemaVersion() {
return CURRENT_SCHEMA_VERSION_REALM;
return Constants.CURRENT_SCHEMA_VERSION_REALM;
}
@Override
@ -888,7 +888,7 @@ public class JpaRealmEntity extends MapRealmEntity.AbstractRealmEntity implement
public void addComponent(MapComponentEntity component) {
JpaComponentEntity jpaComponent = JpaComponentEntity.class.cast(CLONER.from(component));
jpaComponent.setParent(this);
jpaComponent.setEntityVersion(this.getEntityVersion());
jpaComponent.setEntityVersion(Constants.CURRENT_SCHEMA_VERSION_COMPONENT);
this.components.add(jpaComponent);
}

View file

@ -45,6 +45,7 @@ import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.storage.jpa.Constants;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
import org.keycloak.models.map.user.MapUserConsentEntity;
@ -52,7 +53,6 @@ import org.keycloak.models.map.user.MapUserCredentialEntity;
import org.keycloak.models.map.user.MapUserEntity;
import org.keycloak.models.map.user.MapUserFederatedIdentityEntity;
import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_USER;
import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.CLONER;
/**
@ -198,7 +198,7 @@ public class JpaUserEntity extends MapUserEntity.AbstractUserEntity implements J
@Override
public Integer getCurrentSchemaVersion() {
return CURRENT_SCHEMA_VERSION_USER;
return Constants.CURRENT_SCHEMA_VERSION_USER;
}
@Override
@ -470,7 +470,7 @@ public class JpaUserEntity extends MapUserEntity.AbstractUserEntity implements J
public void addUserConsent(MapUserConsentEntity userConsentEntity) {
JpaUserConsentEntity entity = (JpaUserConsentEntity) CLONER.from(userConsentEntity);
entity.setParent(this);
entity.setEntityVersion(this.getEntityVersion());
entity.setEntityVersion(Constants.CURRENT_SCHEMA_VERSION_USER_CONSENT);
this.consents.add(entity);
}
@ -523,7 +523,7 @@ public class JpaUserEntity extends MapUserEntity.AbstractUserEntity implements J
public void addFederatedIdentity(MapUserFederatedIdentityEntity federatedIdentity) {
JpaUserFederatedIdentityEntity entity = (JpaUserFederatedIdentityEntity) CLONER.from(federatedIdentity);
entity.setParent(this);
entity.setEntityVersion(this.getEntityVersion());
entity.setEntityVersion(Constants.CURRENT_SCHEMA_VERSION_USER_FEDERATED_IDENTITY);
this.federatedIdentities.add(entity);
}

View file

@ -347,7 +347,7 @@ public class JpaUserSessionEntity extends AbstractUserSessionEntity implements J
public void addAuthenticatedClientSession(MapAuthenticatedClientSessionEntity clientSession) {
JpaClientSessionEntity jpaClientSession = JpaClientSessionEntity.class.cast(CLONER.from(clientSession));
jpaClientSession.setParent(this);
jpaClientSession.setEntityVersion(this.getEntityVersion());
jpaClientSession.setEntityVersion(Constants.CURRENT_SCHEMA_VERSION_CLIENT_SESSION);
clientSessions.add(jpaClientSession);
}