From 19a545049b31fbcbd3b8a50f44674b989b7b4716 Mon Sep 17 00:00:00 2001 From: mposolda Date: Wed, 18 Jun 2014 12:31:55 +0200 Subject: [PATCH] KEYCLOAK-536 Fix Sybase - role can't be used as column name as it's keyword in sybase --- .../main/java/org/keycloak/models/jpa/ApplicationAdapter.java | 2 +- .../src/main/java/org/keycloak/models/jpa/RealmAdapter.java | 2 +- .../models/jpa/entities/AbstractRoleMappingEntity.java | 3 +++ .../main/java/org/keycloak/models/jpa/entities/RoleEntity.java | 2 +- .../org/keycloak/models/jpa/entities/ScopeMappingEntity.java | 3 +++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java index 36ea18247a..11ee6f07b9 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/ApplicationAdapter.java @@ -142,7 +142,7 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode applicationEntity.getRoles().remove(role); applicationEntity.getDefaultRoles().remove(role); - em.createNativeQuery("delete from CompositeRole where role = :role").setParameter("role", role).executeUpdate(); + em.createNativeQuery("delete from CompositeRole where childRole = :role").setParameter("role", role).executeUpdate(); em.createQuery("delete from " + ScopeMappingEntity.class.getSimpleName() + " where role = :role").setParameter("role", role).executeUpdate(); em.createQuery("delete from " + UserRoleMappingEntity.class.getSimpleName() + " where role = :role").setParameter("role", role).executeUpdate(); role.setApplication(null); 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 fb92f1432b..18fc1db8ff 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 @@ -928,7 +928,7 @@ public class RealmAdapter implements RealmModel { realm.getRoles().remove(role); realm.getDefaultRoles().remove(role); - em.createNativeQuery("delete from CompositeRole where role = :role").setParameter("role", roleEntity).executeUpdate(); + em.createNativeQuery("delete from CompositeRole where childRole = :role").setParameter("role", roleEntity).executeUpdate(); em.createQuery("delete from " + UserRoleMappingEntity.class.getSimpleName() + " where role = :role").setParameter("role", roleEntity).executeUpdate(); em.createQuery("delete from " + ScopeMappingEntity.class.getSimpleName() + " where role = :role").setParameter("role", roleEntity).executeUpdate(); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AbstractRoleMappingEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AbstractRoleMappingEntity.java index 685aed752c..2ab0d00cc7 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AbstractRoleMappingEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AbstractRoleMappingEntity.java @@ -3,6 +3,7 @@ package org.keycloak.models.jpa.entities; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.MappedSuperclass; @@ -20,7 +21,9 @@ public class AbstractRoleMappingEntity { protected String id; @ManyToOne(fetch= FetchType.LAZY) protected UserEntity user; + @ManyToOne(fetch= FetchType.LAZY) + @JoinColumn(name="roleId") protected RoleEntity role; public String getId() { diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java index 5be5fed2e5..d3fc6dfb8c 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java @@ -59,7 +59,7 @@ public class RoleEntity { private String appRealmConstraint; @ManyToMany(fetch = FetchType.LAZY, cascade = {}) - @JoinTable(name = "CompositeRole", joinColumns = @JoinColumn(name = "composite"), inverseJoinColumns = @JoinColumn(name = "role")) + @JoinTable(name = "CompositeRole", joinColumns = @JoinColumn(name = "composite"), inverseJoinColumns = @JoinColumn(name = "childRole")) private Collection compositeRoles = new ArrayList(); public String getId() { diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ScopeMappingEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ScopeMappingEntity.java index e1a00f9838..b45b69b8e4 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ScopeMappingEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ScopeMappingEntity.java @@ -6,6 +6,7 @@ import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -27,7 +28,9 @@ public class ScopeMappingEntity { protected String id; @ManyToOne(fetch= FetchType.LAZY) protected ClientEntity client; + @ManyToOne(fetch= FetchType.LAZY) + @JoinColumn(name="roleId") protected RoleEntity role; public String getId() {