diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java index 9987e149d3..31c129b1b0 100644 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java @@ -1063,7 +1063,7 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, ClientSc private RealmLocalizationTextsEntity getRealmLocalizationTextsEntity(String locale, String realmId) { RealmLocalizationTextsEntity.RealmLocalizationTextEntityKey key = new RealmLocalizationTextsEntity.RealmLocalizationTextEntityKey(); - key.setRealmId(realmId); + key.setRealm(em.getReference(RealmEntity.class, realmId)); key.setLocale(locale); return em.find(RealmLocalizationTextsEntity.class, key); } @@ -1086,7 +1086,7 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, ClientSc RealmLocalizationTextsEntity entity = getRealmLocalizationTextsEntity(locale, realm.getId()); if(entity == null) { entity = new RealmLocalizationTextsEntity(); - entity.setRealmId(realm.getId()); + entity.setRealm(em.getReference(RealmEntity.class, realm.getId())); entity.setLocale(locale); entity.setTexts(new HashMap<>()); em.persist(entity); @@ -1099,7 +1099,7 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, ClientSc RealmLocalizationTextsEntity entity = new RealmLocalizationTextsEntity(); entity.setTexts(localizationTexts); entity.setLocale(locale); - entity.setRealmId(realm.getId()); + entity.setRealm(em.getReference(RealmEntity.class, realm.getId())); em.merge(entity); } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index 919cb8e323..2ffc935bb9 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -2209,7 +2209,7 @@ public class RealmAdapter implements LegacyRealmModel, JpaModel { } else { RealmLocalizationTextsEntity realmLocalizationTextsEntity = new RealmLocalizationTextsEntity(); - realmLocalizationTextsEntity.setRealmId(realm.getId()); + realmLocalizationTextsEntity.setRealm(realm); realmLocalizationTextsEntity.setLocale(locale); realmLocalizationTextsEntity.setTexts(localizationTexts); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java index be24322156..0fb5445ac5 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java @@ -237,7 +237,7 @@ public class RealmEntity { @Column(name="ALLOW_USER_MANAGED_ACCESS") private boolean allowUserManagedAccess; - @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realmId") + @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") @MapKey(name="locale") Map realmLocalizationTexts = new HashMap<>(); @@ -842,6 +842,13 @@ public class RealmEntity { return true; } + public String toString() { + return "Realm{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } + @Override public int hashCode() { return id.hashCode(); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmLocalizationTextsEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmLocalizationTextsEntity.java index 98794092b2..5e80c4682b 100644 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmLocalizationTextsEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmLocalizationTextsEntity.java @@ -23,8 +23,11 @@ import java.util.Objects; import jakarta.persistence.Column; import jakarta.persistence.Convert; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.IdClass; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import org.hibernate.annotations.Mutability; @@ -36,15 +39,15 @@ import org.keycloak.models.jpa.converter.MapStringConverter; @Table(name = "REALM_LOCALIZATIONS") public class RealmLocalizationTextsEntity { static public class RealmLocalizationTextEntityKey implements Serializable { - private String realmId; + private RealmEntity realm; private String locale; - public String getRealmId() { - return realmId; + public RealmEntity getRealm() { + return realm; } - public void setRealmId(String realmId) { - this.realmId = realmId; + public void setRealm(RealmEntity realm) { + this.realm = realm; } public String getLocale() { @@ -60,19 +63,20 @@ public class RealmLocalizationTextsEntity { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RealmLocalizationTextEntityKey that = (RealmLocalizationTextEntityKey) o; - return Objects.equals(realmId, that.realmId) && + return Objects.equals(realm, that.realm) && Objects.equals(locale, that.locale); } @Override public int hashCode() { - return Objects.hash(realmId, locale); + return Objects.hash(realm, locale); } } @Id - @Column(name = "REALM_ID") - private String realmId; + @ManyToOne(fetch= FetchType.LAZY) + @JoinColumn(name = "REALM_ID") + private RealmEntity realm; @Id @Column(name = "LOCALE") @@ -105,20 +109,20 @@ public class RealmLocalizationTextsEntity { this.locale = locale; } - public String getRealmId() { - return realmId; + public RealmEntity getRealm() { + return realm; } - public void setRealmId(String realmId) { - this.realmId = realmId; + public void setRealm(RealmEntity realm) { + this.realm = realm; } @Override public String toString() { return "LocalizationTextEntity{" + - ", text='" + texts + '\'' + + "text='" + texts + '\'' + ", locale='" + locale + '\'' + - ", realmId='" + realmId + '\'' + + ", realm='" + realm + '\'' + '}'; } @@ -127,13 +131,13 @@ public class RealmLocalizationTextsEntity { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RealmLocalizationTextsEntity that = (RealmLocalizationTextsEntity) o; - return Objects.equals(realmId, that.realmId) && + return Objects.equals(realm, that.realm) && Objects.equals(locale, that.locale) && Objects.equals(texts, that.texts); } @Override public int hashCode() { - return Objects.hash(realmId, locale, texts); + return Objects.hash(realm, locale, texts); } }