Results of AttributeConverters are mutable; workaround a regression in H6
Relates to #16551
This commit is contained in:
parent
fa3ba6331e
commit
80f7452950
3 changed files with 25 additions and 1 deletions
|
@ -1083,9 +1083,9 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, ClientSc
|
|||
entity.setRealmId(realm.getId());
|
||||
entity.setLocale(locale);
|
||||
entity.setTexts(new HashMap<>());
|
||||
em.persist(entity);
|
||||
}
|
||||
entity.getTexts().put(key, text);
|
||||
em.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
package org.keycloak.models.jpa.converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import org.hibernate.type.descriptor.java.MutableMutabilityPlan;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
|
@ -45,4 +47,19 @@ public class MapStringConverter implements AttributeConverter<Map<String, String
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutability plan for this property. Needed in Hibernate 6 as it doesn't assume mutability by default
|
||||
* in contrast to Hibernate 5.
|
||||
* This is tracked in the upstream project in <a href="https://hibernate.atlassian.net/browse/HHH-16081">HHH-16081</a>
|
||||
*/
|
||||
public static class MapStringConverterMutabilityPlan extends MutableMutabilityPlan<Map<String, String>> {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> deepCopyNotNull(Map<String, String> value) {
|
||||
return new HashMap<>(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.IdClass;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Mutability;
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.keycloak.models.jpa.converter.MapStringConverter;
|
||||
|
||||
|
@ -80,6 +81,12 @@ public class RealmLocalizationTextsEntity {
|
|||
@Nationalized
|
||||
@Column(name = "TEXTS")
|
||||
@Convert(converter = MapStringConverter.class)
|
||||
/*
|
||||
* @Mutability annotation needed in Hibernate 6 as it doesn't assume mutability by default
|
||||
* in contrast to Hibernate 5.
|
||||
* This is tracked in the upstream project in https://hibernate.atlassian.net/browse/HHH-16081
|
||||
*/
|
||||
@Mutability(MapStringConverter.MapStringConverterMutabilityPlan.class)
|
||||
private Map<String,String> texts;
|
||||
|
||||
public Map<String,String> getTexts() {
|
||||
|
|
Loading…
Reference in a new issue