db schema

This commit is contained in:
Bill Burke 2014-07-17 16:32:36 -04:00
parent 20cde9cd00
commit aa2d1bcc93
17 changed files with 163 additions and 85 deletions

View file

@ -145,7 +145,7 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
applicationEntity.getRoles().remove(role);
applicationEntity.getDefaultRoles().remove(role);
em.createNativeQuery("delete from CompositeRole where childRole = :role").setParameter("role", role).executeUpdate();
em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", role).executeUpdate();
em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", role).executeUpdate();
role.setApplication(null);
em.flush();

View file

@ -769,7 +769,7 @@ public class RealmAdapter implements RealmModel {
realm.getRoles().remove(role);
realm.getDefaultRoles().remove(role);
em.createNativeQuery("delete from CompositeRole where childRole = :role").setParameter("role", roleEntity).executeUpdate();
em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", roleEntity).executeUpdate();
em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", roleEntity).executeUpdate();
em.remove(roleEntity);

View file

@ -15,6 +15,7 @@ import org.keycloak.models.jpa.entities.UserAttributeEntity;
import org.keycloak.models.jpa.entities.UserEntity;
import org.keycloak.models.jpa.entities.UserRequiredActionEntity;
import org.keycloak.models.jpa.entities.UserRoleMappingEntity;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.Pbkdf2PasswordEncoder;
import javax.persistence.EntityManager;
@ -215,6 +216,7 @@ public class UserAdapter implements UserModel {
if (credentialEntity == null) {
credentialEntity = new CredentialEntity();
credentialEntity.setId(KeycloakModelUtils.generateId());
credentialEntity.setType(cred.getType());
credentialEntity.setDevice(cred.getDevice());
credentialEntity.setUser(user);
@ -276,6 +278,7 @@ public class UserAdapter implements UserModel {
if (credentialEntity == null) {
credentialEntity = new CredentialEntity();
credentialEntity.setId(KeycloakModelUtils.generateId());
credentialEntity.setType(credModel.getType());
credentialEntity.setUser(user);
em.persist(credentialEntity);

View file

@ -1,10 +1,12 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Collection;
@ -15,16 +17,23 @@ import java.util.Collection;
@Entity
public class ApplicationEntity extends ClientEntity {
@Column(name="SURROGATE_AUTH_REQUIRED")
private boolean surrogateAuthRequired;
@Column(name="BASE_URL")
private String baseUrl;
@Column(name="MANAGEMENT_URL")
private String managementUrl;
@Column(name="BEARER_ONLY")
private boolean bearerOnly;
@OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "application")
Collection<RoleEntity> roles = new ArrayList<RoleEntity>();
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="ApplicationDefaultRoles")
@JoinTable(name="APPLICATION_DEFAULT_ROLES")
Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>();
public boolean isSurrogateAuthRequired() {

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@ -9,6 +10,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.io.Serializable;
/**
@ -17,12 +19,15 @@ import java.io.Serializable;
@NamedQueries({
@NamedQuery(name="deleteAuthenticationLinksByRealm", query="delete from AuthenticationLinkEntity authLink where authLink.user IN (select u from UserEntity u where u.realmId=:realmId)")
})
@Table(name="AUTHENTICATION_LINK")
@Entity
@IdClass(AuthenticationLinkEntity.Key.class)
public class AuthenticationLinkEntity {
@Id
@Column(name="AUTH_PROVIDER")
protected String authProvider;
@Column(name="AUTH_USER_ID")
protected String authUserId;
// NOTE: @OnetoOne creates a constraint race condition if the join column is on AuthenticationLinkEntity.
@ -30,7 +35,7 @@ public class AuthenticationLinkEntity {
// a @ManyToOne on both sides. Broken yes, but, I think we're going to replace AuthenticationLinkEntity anyways.
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="userId")
@JoinColumn(name="USER_ID")
protected UserEntity user;
public String getAuthProvider() {

View file

@ -18,23 +18,27 @@ import java.util.Map;
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@Entity
@Table(name="AuthProviderEntity")
@Table(name="AUTH_PROVIDER_ENTITY")
@IdClass(AuthenticationProviderEntity.Key.class)
public class AuthenticationProviderEntity {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "REALM_ID")
protected RealmEntity realm;
@Id
@Column(name="PROVIDER_NAME")
private String providerName;
@Column(name="PASSWORD_UPDATE_SUPPORTED")
private boolean passwordUpdateSupported;
@Column(name="PRIORITY")
private int priority;
@ElementCollection
@MapKeyColumn(name="name")
@Column(name="value")
@CollectionTable(name="AuthProviderEntity_cfg")
@CollectionTable(name="AUTH_PROVIDER_CONFIG")
private Map<String, String> config;
public RealmEntity getRealm() {

View file

@ -21,28 +21,34 @@ import java.util.Set;
*/
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"realm", "name"})})
@Table(name="CLIENT", uniqueConstraints = {@UniqueConstraint(columnNames = {"REALM_ID", "NAME"})})
public abstract class ClientEntity {
@Id
@Column(length = 36)
@Column(name="ID", length = 36)
private String id;
@Column(name = "name")
@Column(name = "NAME")
private String name;
@Column(name="ENABLED")
private boolean enabled;
@Column(name="SECRET")
private String secret;
@Column(name="ALLOWED_CLAIMS_MASK")
private long allowedClaimsMask;
@Column(name="NOT_BEFORE")
private int notBefore;
@Column(name="PUBLIC_CLIENT")
private boolean publicClient;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "realm")
@JoinColumn(name = "REALM_ID")
protected RealmEntity realm;
@ElementCollection
@CollectionTable
@CollectionTable(name = "WEB_ORIGINS")
protected Set<String> webOrigins = new HashSet<String>();
@ElementCollection
@CollectionTable
@CollectionTable(name = "REDIRECT_URIS")
protected Set<String> redirectUris = new HashSet<String>();
public RealmEntity getRealm() {

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@ -8,6 +9,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable;
/**
@ -19,22 +21,36 @@ import java.io.Serializable;
@NamedQuery(name="deleteCredentialsByRealm", query="delete from CredentialEntity cred where cred.user IN (select u from UserEntity u where u.realmId=:realmId)")
})
@Table(name="CREDENTIAL")
@Entity
@IdClass(CredentialEntity.Key.class)
public class CredentialEntity {
@Id
@Column(length = 36)
protected String id;
@Column(name="TYPE")
protected String type;
@Column(name="VALUE")
protected String value;
@Column(name="DEVICE")
protected String device;
@Column(name="SALT")
protected byte[] salt;
@Column(name="HASH_ITERATIONS")
protected int hashIterations;
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="userId")
@JoinColumn(name="USER_ID")
protected UserEntity user;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getValue() {
return value;
}
@ -82,48 +98,4 @@ public class CredentialEntity {
public void setHashIterations(int hashIterations) {
this.hashIterations = hashIterations;
}
public static class Key implements Serializable {
protected UserEntity user;
protected String type;
public Key() {
}
public Key(UserEntity user, String type) {
this.user = user;
this.type = type;
}
public UserEntity getUser() {
return user;
}
public String getType() {
return type;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Key key = (Key) o;
if (type != null ? !type.equals(key.type) : key.type != null) return false;
if (user != null ? !user.getId().equals(key.user != null ? key.user.getId() : null) : key.user != null) return false;
return true;
}
@Override
public int hashCode() {
int result = user != null ? user.getId().hashCode() : 0;
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
}
}
}

View file

@ -1,6 +1,8 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@ -15,6 +17,7 @@ import javax.persistence.NamedQuery;
})
@Entity
public class OAuthClientEntity extends ClientEntity {
@Column(name="DIRECT_GRANTS_ONLY")
protected boolean directGrantsOnly;
public boolean isDirectGrantsOnly() {

View file

@ -8,12 +8,14 @@ import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.MapKeyColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -26,6 +28,7 @@ import java.util.Set;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
@Table(name="REALM")
@Entity
@NamedQueries({
@NamedQuery(name="getAllRealms", query="select realm from RealmEntity realm"),
@ -33,59 +36,85 @@ import java.util.Set;
})
public class RealmEntity {
@Id
@Column(length = 36)
@Column(name="ID", length = 36)
protected String id;
@Column(unique = true)
@Column(name="NAME", unique = true)
protected String name;
@Column(name="ENABLED")
protected boolean enabled;
@Column(name="SSL_NOT_REQUIRED")
protected boolean sslNotRequired;
@Column(name="REGISTRATION_ALLOWED")
protected boolean registrationAllowed;
@Column(name="PASSWORD_CRED_GRANT_ALLOWED")
protected boolean passwordCredentialGrantAllowed;
@Column(name="VERIFY_EMAIL")
protected boolean verifyEmail;
@Column(name="RESET_PASSWORD_ALLOWED")
protected boolean resetPasswordAllowed;
@Column(name="SOCIAL")
protected boolean social;
@Column(name="REMEMBER_ME")
protected boolean rememberMe;
//--- brute force settings
@Column(name="BRUTE_FORCE_PROTECTED")
protected boolean bruteForceProtected;
@Column(name="MAX_FAILURE_WAIT")
protected int maxFailureWaitSeconds;
@Column(name="MINIMUM_QUICK_LOGIN_WAIT")
protected int minimumQuickLoginWaitSeconds;
@Column(name="WAIT_INCREMENT_SECONDS")
protected int waitIncrementSeconds;
@Column(name="QUICK_LOGIN_CHECK")
protected long quickLoginCheckMilliSeconds;
@Column(name="MAX_DELTA_TIME")
protected int maxDeltaTimeSeconds;
@Column(name="FAILURE_FACTOR")
protected int failureFactor;
//--- end brute force settings
@Column(name="updateProfileOnInitSocLogin")
@Column(name="UPDATE_PROFILE_ON_SOC_LOGIN")
protected boolean updateProfileOnInitialSocialLogin;
@Column(name="PASSWORD_POLICY")
protected String passwordPolicy;
@Column(name="SSO_IDLE_TIMEOUT")
private int ssoSessionIdleTimeout;
@Column(name="SSO_MAX_LIFESPAN")
private int ssoSessionMaxLifespan;
@Column(name="ACCESS_TOKEN_LIFESPAN")
protected int accessTokenLifespan;
@Column(name="ACCESS_CODE_LIFESPAN")
protected int accessCodeLifespan;
@Column(name="USER_ACTION_LIFESPAN")
protected int accessCodeLifespanUserAction;
@Column(name="NOT_BEFORE")
protected int notBefore;
@Column(length = 2048)
@Column(name="PUBLIC_KEY", length = 2048)
protected String publicKeyPem;
@Column(length = 2048)
@Column(name="PRIVATE_KEY", length = 2048)
protected String privateKeyPem;
@Column(name="LOGIN_THEME")
protected String loginTheme;
@Column(name="ACCOUNT_THEME")
protected String accountTheme;
@Column(name="ADMIN_THEME")
protected String adminTheme;
@Column(name="EMAIL_THEME")
protected String emailTheme;
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="User_RequiredCreds")
@JoinTable(name="USER_REQUIRED_CREDS")
Collection<RequiredCredentialEntity> requiredCredentials = new ArrayList<RequiredCredentialEntity>();
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="AuthProviders")
@JoinTable(name="AUTH_PROVIDERS")
List<AuthenticationProviderEntity> authenticationProviders = new ArrayList<AuthenticationProviderEntity>();
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@ -97,32 +126,36 @@ public class RealmEntity {
@ElementCollection
@MapKeyColumn(name="name")
@Column(name="value")
@CollectionTable
@CollectionTable(name="REALM_SMTP_CONFIG")
protected Map<String, String> smtpConfig = new HashMap<String, String>();
@ElementCollection
@MapKeyColumn(name="name")
@Column(name="value")
@CollectionTable
@CollectionTable(name="REALM_SOCIAL_CONFIG")
protected Map<String, String> socialConfig = new HashMap<String, String>();
@ElementCollection
@MapKeyColumn(name="name")
@Column(name="value")
@CollectionTable
@CollectionTable(name="REALM_LDAP_CONFIG")
protected Map<String, String> ldapServerConfig = new HashMap<String, String>();
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="RealmDefaultRoles")
@JoinTable(name="REALM_DEFAULT_ROLES")
protected Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>();
@Column(name="AUDIT_ENABLED")
protected boolean auditEnabled;
@Column(name="AUDIT_EXPIRATION")
protected long auditExpiration;
@ElementCollection
@CollectionTable(name="REALM_AUDIT_LISTENERS")
protected Set<String> auditListeners= new HashSet<String>();
@OneToOne
@JoinColumn(name="MASTER_ADMIN_APP")
protected ApplicationEntity masterAdminApp;
public String getId() {

View file

@ -1,30 +1,37 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.io.Serializable;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
@Table(name="REALM_REQUIRED_CREDENTIAL")
@Entity
@IdClass(RequiredCredentialEntity.Key.class)
public class RequiredCredentialEntity {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "realm")
@JoinColumn(name = "REALM_ID")
protected RealmEntity realm;
@Id
@Column(name = "TYPE")
protected String type;
@Column(name = "INPUT")
protected boolean input;
@Column(name = "SECRET")
protected boolean secret;
@Column(name = "FORM_LABEL")
protected String formLabel;
public RealmEntity getRealm() {

View file

@ -20,8 +20,8 @@ import java.util.Collection;
* @version $Revision: 1 $
*/
@Entity
@Table(uniqueConstraints = {
@UniqueConstraint(columnNames = { "name", "appRealmConstraint" })
@Table(name="KEYCLOAK_ROLE", uniqueConstraints = {
@UniqueConstraint(columnNames = { "NAME", "APP_REALM_CONSTRAINT" })
})
@NamedQueries({
@NamedQuery(name="getAppRoleByName", query="select role from RoleEntity role where role.name = :name and role.application = :application"),
@ -33,29 +33,32 @@ public class RoleEntity {
@Column(name="id", length = 36)
private String id;
@Column(name = "NAME")
private String name;
@Column(name = "DESCRIPTION")
private String description;
// hax! couldn't get constraint to work properly
@Column(name = "REALM_ID")
private String realmId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "realm")
@JoinColumn(name = "REALM")
private RealmEntity realm;
@Column(name="applicationRole")
@Column(name="APPLICATION_ROLE")
private boolean applicationRole;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application")
@JoinColumn(name = "APPLICATION")
private ApplicationEntity application;
// Hack to ensure that either name+application or name+realm are unique. Needed due to MS-SQL as it don't allow multiple NULL values in the column, which is part of constraint
@Column(length = 36)
@Column(name="APP_REALM_CONSTRAINT", length = 36)
private String appRealmConstraint;
@ManyToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "CompositeRole", joinColumns = @JoinColumn(name = "composite"), inverseJoinColumns = @JoinColumn(name = "childRole"))
@JoinTable(name = "COMPOSITE_ROLE", joinColumns = @JoinColumn(name = "COMPOSITE"), inverseJoinColumns = @JoinColumn(name = "CHILD_ROLE"))
private Collection<RoleEntity> compositeRoles = new ArrayList<RoleEntity>();
public String getId() {

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@ -8,6 +9,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable;
/**
@ -21,17 +23,19 @@ import java.io.Serializable;
@NamedQuery(name="deleteScopeMappingByRole", query="delete from ScopeMappingEntity where role = :role"),
@NamedQuery(name="deleteScopeMappingByClient", query="delete from ScopeMappingEntity where client = :client")
})
@Table(name="SCOPE_MAPPING")
@Entity
@IdClass(ScopeMappingEntity.Key.class)
public class ScopeMappingEntity {
@Id
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name = "CLIENT_ID")
protected ClientEntity client;
@Id
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="roleId")
@JoinColumn(name="ROLE_ID")
protected RoleEntity role;
public ClientEntity getClient() {

View file

@ -1,12 +1,15 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable;
/**
@ -20,19 +23,25 @@ import java.io.Serializable;
@NamedQuery(name="deleteSocialLinkByRealm", query="delete from SocialLinkEntity social where social.user IN (select u from UserEntity u where realmId=:realmId)"),
@NamedQuery(name="deleteSocialLinkByUser", query="delete from SocialLinkEntity social where social.user = :user")
})
@Table(name="USER_SOCIAL_LINK")
@Entity
@IdClass(SocialLinkEntity.Key.class)
public class SocialLinkEntity {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
private UserEntity user;
@Column(name = "REALM_ID")
protected String realmId;
@Id
@Column(name = "SOCIAL_PROVIDER")
protected String socialProvider;
@Column(name = "SOCIAL_USER_ID")
protected String socialUserId;
@Column(name = "SOCIAL_USERNAME")
protected String socialUsername;
public UserEntity getUser() {

View file

@ -1,12 +1,15 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable;
/**
@ -16,16 +19,20 @@ import java.io.Serializable;
@NamedQueries({
@NamedQuery(name="deleteUserAttributesByRealm", query="delete from UserAttributeEntity attr where attr.user IN (select u from UserEntity u where u.realmId=:realmId)")
})
@Table(name="USER_ATTRIBUTE")
@Entity
@IdClass(UserAttributeEntity.Key.class)
public class UserAttributeEntity {
@Id
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name = "USER_ID")
protected UserEntity user;
@Id
@Column(name = "NAME")
protected String name;
@Column(name = "VALUE")
protected String value;
public String getName() {

View file

@ -42,26 +42,35 @@ import java.util.Set;
@NamedQuery(name="deleteUsersByRealm", query="delete from UserEntity u where u.realmId = :realmId")
})
@Entity
@Table(uniqueConstraints = {
@UniqueConstraint(columnNames = { "realmId", "username" }),
@UniqueConstraint(columnNames = { "realmId", "emailConstraint" })
@Table(name="USER", uniqueConstraints = {
@UniqueConstraint(columnNames = { "REALM_ID", "USERNAME" }),
@UniqueConstraint(columnNames = { "REALM_ID", "EMAIL_CONSTRAINT" })
})
public class UserEntity {
@Id
@Column(length = 36)
@Column(name="ID", length = 36)
protected String id;
@Column(name = "USERNAME")
protected String username;
@Column(name = "FIRST_NAME")
protected String firstName;
@Column(name = "LAST_NAME")
protected String lastName;
@Column(name = "EMAIL")
protected String email;
@Column(name = "ENABLED")
protected boolean enabled;
@Column(name = "TOTP")
protected boolean totp;
@Column(name = "EMAIL_VERIFIED")
protected boolean emailVerified;
// Hack just to workaround the fact that on MS-SQL you can't have unique constraint with multiple NULL values TODO: Find better solution (like unique index with 'where' but that's proprietary)
@Column(name = "EMAIL_CONSTRAINT")
protected String emailConstraint = KeycloakModelUtils.generateId();
@Column(name = "REALM_ID")
protected String realmId;
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user")

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
@ -8,6 +9,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable;
/**
@ -23,16 +25,18 @@ import java.io.Serializable;
@NamedQuery(name="deleteUserRoleMappingsByUser", query="delete from UserRoleMappingEntity m where m.user = :user")
})
@Table(name="USER_ROLE_MAPPING")
@Entity
@IdClass(UserRoleMappingEntity.Key.class)
public class UserRoleMappingEntity {
@Id
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="userId")
@JoinColumn(name="USER_ID")
protected UserEntity user;
@Id
@Column(name = "ROLE_ID")
protected String roleId;
public UserEntity getUser() {