Model upgrade Hibernate/JPA

---
Quarkus3 branch sync no. 14 (24.4.2023)
Resolved conflicts:
keycloak/pom.xml - Modified
---
Quarkus3 branch sync no. 13 (11.4.2023)
Resolved conflicts:
keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/JpaMapStorageProviderFactory.java - Modified
---
Quarkus3 branch sync no. 11 (24.3.2023)
Resolved conflicts:
keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/JpaMapStorageProviderFactory.java - Modified
---
Quarkus3 branch sync no. 7 (27.2.2023)
Resolved conflicts:
keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientEntity.java - Modified
keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientScope/entity/JpaClientScopeEntity.java - Modified
keycloak/pom.xml - Modified
---
Quarkus3 branch sync no. 6 (17.2.2023)
Resolved conflicts:
keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/JpaMapStorageProviderFactory.java - Modified
---
Quarkus3 branch sync no. 1 (18.1.2023)
Resolved conflicts:
keycloak/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/hibernate/dialect/JsonbPostgreSQL95Dialect.java - Modified
This commit is contained in:
Stefan Guilhen 2023-01-04 16:38:14 +01:00 committed by Václav Muzikář
parent 25862a15ad
commit e505021681
48 changed files with 136 additions and 192 deletions

View file

@ -53,7 +53,7 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<artifactId>infinispan-core-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
@ -63,6 +63,10 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-jboss-marshalling</artifactId>
</dependency>
<!--dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.3_spec</artifactId>
</dependency-->
<!-- Needed for externalizers in package "org.keycloak.models.sessions.infinispan.entities.wildfly" .
Hopefully can be removed once we start to use the protobuf marshalling -->

View file

@ -1,10 +1,8 @@
package org.keycloak.models.sessions.infinispan.initializer;
import org.infinispan.Cache;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.cache.VersioningScheme;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;

View file

@ -75,7 +75,7 @@
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>

View file

@ -30,14 +30,12 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;

View file

@ -40,7 +40,6 @@ import org.keycloak.authorization.model.Policy;
import org.keycloak.authorization.model.Resource;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.PolicyStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.RealmModel;

View file

@ -23,7 +23,6 @@ import org.keycloak.authorization.jpa.entities.ResourceEntity;
import org.keycloak.authorization.jpa.entities.ResourceServerEntity;
import org.keycloak.authorization.jpa.entities.ScopeEntity;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.ResourceServerStore;
import org.keycloak.models.ModelException;
import org.keycloak.models.RealmModel;

View file

@ -21,7 +21,6 @@ import org.keycloak.authorization.jpa.entities.ResourceEntity;
import org.keycloak.authorization.model.Resource;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.ResourceStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.RealmModel;

View file

@ -34,7 +34,6 @@ import org.keycloak.authorization.AuthorizationProvider;
import org.keycloak.authorization.jpa.entities.ScopeEntity;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.ScopeStore;
import org.keycloak.models.RealmModel;
import org.keycloak.models.utils.KeycloakModelUtils;

View file

@ -28,7 +28,6 @@ import org.keycloak.authorization.model.Policy;
import org.keycloak.authorization.model.Resource;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.jpa.JpaModel;

View file

@ -24,7 +24,6 @@ import org.keycloak.authorization.model.Policy;
import org.keycloak.authorization.model.Resource;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.jpa.JpaModel;
import org.keycloak.representations.idm.authorization.DecisionStrategy;

View file

@ -23,7 +23,6 @@ import org.keycloak.authorization.model.AbstractAuthorizationModel;
import org.keycloak.authorization.model.Resource;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.models.jpa.JpaModel;

View file

@ -20,7 +20,6 @@ import org.keycloak.authorization.jpa.entities.ScopeEntity;
import org.keycloak.authorization.model.AbstractAuthorizationModel;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.jpa.JpaModel;

View file

@ -17,8 +17,6 @@
package org.keycloak.connections.jpa.util;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
import org.jboss.logging.Logger;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
@ -175,7 +173,6 @@ public class JpaUtils {
* should exist inside the jar file. The default file contains all the
* needed queries and the specific one can overload all or some of them for
* that database type.
* @param em The entity manager to use
* @param databaseType The database type as managed in
* @return
*/
@ -224,11 +221,11 @@ public class JpaUtils {
SessionFactoryImplementor sessionFactory = entityManager.getEntityManagerFactory().unwrap(SessionFactoryImplementor.class);
if (isNative) {
NativeSQLQuerySpecification spec = new NativeSQLQuerySpecification(querySql, new NativeSQLQueryReturn[0], Collections.emptySet());
sessionFactory.getQueryPlanCache().getNativeSQLQueryPlan(spec);
// NativeSQLQuerySpecification spec = new NativeSQLQuerySpecification(querySql, new NativeSQLQueryReturn[0], Collections.emptySet());
// sessionFactory.getQueryPlanCache().getNativeSQLQueryPlan(spec);
sessionFactory.addNamedQuery(queryName, entityManager.createNativeQuery(querySql));
} else {
sessionFactory.getQueryPlanCache().getHQLQueryPlan(querySql, false, Collections.emptyMap());
// sessionFactory.getQueryPlanCache().getHQLQueryPlan(querySql, false, Collections.emptyMap());
sessionFactory.addNamedQuery(queryName, entityManager.createQuery(querySql));
}
}

View file

@ -26,7 +26,6 @@ import org.keycloak.models.RoleModel;
import org.keycloak.models.jpa.entities.ClientScopeAttributeEntity;
import org.keycloak.models.jpa.entities.ClientScopeEntity;
import org.keycloak.models.jpa.entities.ProtocolMapperEntity;
import org.keycloak.models.jpa.entities.RoleEntity;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.RoleUtils;

View file

@ -19,20 +19,15 @@ package org.keycloak.models.jpa.entities;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -25,7 +25,6 @@ import jakarta.persistence.Id;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table;
import java.util.Date;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -17,22 +17,14 @@
package org.keycloak.storage.jpa.entity;
import org.keycloak.models.jpa.entities.UserEntity;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -38,7 +38,7 @@
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>

View file

@ -46,11 +46,15 @@ import jakarta.transaction.RollbackException;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.SessionImpl;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.service.ServiceRegistry;
import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.authorization.model.PermissionTicket;
@ -419,6 +423,12 @@ public class JpaMapStorageProviderFactory implements
// Pass on the property to 'EventListenerIntegrator' to activate the necessary event listeners for JPA map storage
properties.put(EventListenerIntegrator.JPA_MAP_STORAGE_ENABLED, Boolean.TRUE.toString());
// register custom jsonb type
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
MetadataSources sources = new MetadataSources(standardRegistry);
MetadataBuilder metadataBuilder = sources.getMetadataBuilder();
metadataBuilder.applyBasicType(JsonbType.INSTANCE);
logger.trace("Creating EntityManagerFactory");
ParsedPersistenceXmlDescriptor descriptor = PersistenceXmlParser.locateIndividualPersistenceUnit(
JpaMapStorageProviderFactory.class.getClassLoader()

View file

@ -18,8 +18,6 @@
package org.keycloak.models.map.storage.jpa;
import org.hibernate.Session;
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.jboss.logging.Logger;
@ -149,11 +147,12 @@ public class JpaMapUtils {
SessionFactoryImplementor sessionFactory = entityManager.getEntityManagerFactory().unwrap(SessionFactoryImplementor.class);
if (isNative) {
NativeSQLQuerySpecification spec = new NativeSQLQuerySpecification(querySql, new NativeSQLQueryReturn[0], Collections.emptySet());
sessionFactory.getQueryPlanCache().getNativeSQLQueryPlan(spec);
// deprecation notes mention usage of a new QueryEngine in hibernate 6
// NativeSQLQuerySpecification spec = new NativeSQLQuerySpecification(querySql, new NativeSQLQueryReturn[0], Collections.emptySet());
// sessionFactory.getQueryPlanCache().getNativeSQLQueryPlan(spec);
sessionFactory.addNamedQuery(queryName, entityManager.createNativeQuery(querySql));
} else {
sessionFactory.getQueryPlanCache().getHQLQueryPlan(querySql, false, Collections.emptyMap());
// sessionFactory.getQueryPlanCache().getHQLQueryPlan(querySql, false, Collections.emptyMap());
sessionFactory.addNamedQuery(queryName, entityManager.createQuery(querySql));
}
}

View file

@ -93,8 +93,8 @@ public class JpaRootAuthenticationSessionMapStorage extends JpaMapStorage<JpaRoo
//noinspection JpaQueryApiInspection
Query deleteById =
em.createNamedQuery("deleteRootAuthenticationSessionByIdNoOptimisticLocking");
deleteById.unwrap(NativeQuery.class).addSynchronizedQuerySpace(JpaRootAuthenticationSessionEntity.TABLE_NAME,
JpaAuthenticationSessionEntity.TABLE_NAME);
deleteById.unwrap(NativeQuery.class).addSynchronizedQuerySpace(JpaRootAuthenticationSessionEntity.TABLE_NAME)
.addSynchronizedQuerySpace(JpaAuthenticationSessionEntity.TABLE_NAME);
deleteById.setParameter("id", key);
int deleteCount = deleteById.executeUpdate();
rootAuth.getAuthenticationSessions().forEach(e -> em.detach(e));

View file

@ -30,9 +30,9 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authSession.MapAuthenticationSessionEntity;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UpdatableEntity;
@ -41,7 +41,6 @@ import static org.keycloak.models.map.storage.jpa.authSession.entity.JpaAuthenti
import org.keycloak.models.map.storage.jpa.JpaChildEntity;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
import org.keycloak.sessions.CommonClientSessionModel;
/**
@ -49,7 +48,6 @@ import org.keycloak.sessions.CommonClientSessionModel;
*/
@Entity
@Table(name = TABLE_NAME)
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaAuthenticationSessionEntity extends UpdatableEntity.Impl implements MapAuthenticationSessionEntity, JpaRootVersionedEntity, JpaChildEntity<JpaRootAuthenticationSessionEntity>{
public static final String TABLE_NAME = "kc_auth_session";
@ -67,7 +65,7 @@ public class JpaAuthenticationSessionEntity extends UpdatableEntity.Impl impleme
@Basic(fetch = FetchType.LAZY)
private Integer entityVersion;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaAuthenticationSessionMetadata metadata;

View file

@ -31,16 +31,15 @@ import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authSession.MapAuthenticationSessionEntity;
import org.keycloak.models.map.authSession.MapRootAuthenticationSessionEntity.AbstractRootAuthenticationSessionEntity;
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 static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.CLONER;
import static org.keycloak.models.map.storage.jpa.authSession.entity.JpaRootAuthenticationSessionEntity.TABLE_NAME;
@ -54,7 +53,6 @@ import static org.keycloak.models.map.storage.jpa.authSession.entity.JpaRootAuth
*/
@Entity
@Table(name = TABLE_NAME)
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaRootAuthenticationSessionEntity extends AbstractRootAuthenticationSessionEntity implements JpaRootVersionedEntity {
public static final String TABLE_NAME = "kc_auth_root_session";
@ -68,7 +66,7 @@ public class JpaRootAuthenticationSessionEntity extends AbstractRootAuthenticati
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaRootAuthenticationSessionMetadata metadata;

View file

@ -26,15 +26,14 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity.AbstractMapPermissionTicketEntity;
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;
/**
@ -44,7 +43,6 @@ import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
*/
@Entity
@Table(name = "kc_authz_permission", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "resourceServerId", "scopeId", "resourceId", "owner", "requester"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaPermissionEntity extends AbstractMapPermissionTicketEntity implements JpaRootVersionedEntity {
@Id
@ -56,7 +54,7 @@ public class JpaPermissionEntity extends AbstractMapPermissionTicketEntity imple
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaPermissionMetadata metadata;

View file

@ -19,11 +19,6 @@ package org.keycloak.models.map.storage.jpa.authorization.policy.delegate;
import java.util.UUID;
import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Root;
import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
import org.keycloak.models.map.authorization.entity.MapPolicyEntityFields;
import org.keycloak.models.map.common.EntityField;

View file

@ -36,16 +36,15 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authorization.entity.MapPolicyEntity.AbstractMapPolicyEntity;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.StringKeyConverter;
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.representations.idm.authorization.DecisionStrategy;
import org.keycloak.representations.idm.authorization.Logic;
@ -56,7 +55,6 @@ import org.keycloak.representations.idm.authorization.Logic;
*/
@Entity
@Table(name = "kc_authz_policy", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "resourceServerId", "name"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaPolicyEntity extends AbstractMapPolicyEntity implements JpaRootVersionedEntity {
@Id
@ -68,7 +66,7 @@ public class JpaPolicyEntity extends AbstractMapPolicyEntity implements JpaRootV
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaPolicyMetadata metadata;

View file

@ -38,16 +38,15 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authorization.entity.MapResourceEntity.AbstractMapResourceEntity;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.StringKeyConverter;
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;
/**
@ -57,7 +56,6 @@ import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
*/
@Entity
@Table(name = "kc_authz_resource", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "resourceServerId", "name", "owner"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaResourceEntity extends AbstractMapResourceEntity implements JpaRootVersionedEntity {
@Id
@ -69,7 +67,7 @@ public class JpaResourceEntity extends AbstractMapResourceEntity implements JpaR
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaResourceMetadata metadata;

View file

@ -26,15 +26,14 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authorization.entity.MapResourceServerEntity.AbstractMapResourceServerEntity;
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.representations.idm.authorization.DecisionStrategy;
import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
@ -46,7 +45,6 @@ import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
*/
@Entity
@Table(name = "kc_authz_resource_server", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "clientId"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaResourceServerEntity extends AbstractMapResourceServerEntity implements JpaRootVersionedEntity {
@Id
@ -58,7 +56,7 @@ public class JpaResourceServerEntity extends AbstractMapResourceServerEntity imp
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaResourceServerMetadata metadata;

View file

@ -26,15 +26,14 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.authorization.entity.MapScopeEntity.AbstractMapScopeEntity;
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;
/**
@ -44,7 +43,6 @@ import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
*/
@Entity
@Table(name = "kc_authz_scope", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "resourceServerId", "name"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaScopeEntity extends AbstractMapScopeEntity implements JpaRootVersionedEntity {
@Id
@ -56,7 +54,7 @@ public class JpaScopeEntity extends AbstractMapScopeEntity implements JpaRootVer
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaScopeMetadata metadata;

View file

@ -36,9 +36,9 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.client.MapClientEntity.AbstractClientEntity;
import org.keycloak.models.map.client.MapProtocolMapperEntity;
import org.keycloak.models.map.common.DeepCloner;
@ -61,7 +61,6 @@ import java.util.Optional;
columnNames = {"realmId", "clientId"}
)
})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaClientEntity extends AbstractClientEntity implements JpaRootVersionedEntity {
@Id
@ -73,7 +72,7 @@ public class JpaClientEntity extends AbstractClientEntity implements JpaRootVers
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaClientMetadata metadata;

View file

@ -36,9 +36,9 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.client.MapProtocolMapperEntity;
import org.keycloak.models.map.clientscope.MapClientScopeEntity.AbstractClientScopeEntity;
import org.keycloak.models.map.common.DeepCloner;
@ -56,7 +56,6 @@ import java.util.Optional;
*/
@Entity
@Table(name = "kc_client_scope", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "name"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaClientScopeEntity extends AbstractClientScopeEntity implements JpaRootVersionedEntity {
@Id
@ -68,7 +67,7 @@ public class JpaClientScopeEntity extends AbstractClientScopeEntity implements J
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaClientScopeMetadata metadata;

View file

@ -27,15 +27,14 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.events.admin.OperationType;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.events.MapAdminEventEntity;
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_ADMIN_EVENT;
@ -47,7 +46,6 @@ import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSI
*/
@Entity
@Table(name = "kc_admin_event")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaAdminEventEntity extends MapAdminEventEntity.AbstractAdminEventEntity implements JpaRootVersionedEntity {
@Id
@ -59,7 +57,7 @@ public class JpaAdminEventEntity extends MapAdminEventEntity.AbstractAdminEventE
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaAdminEventMetadata metadata;

View file

@ -33,15 +33,14 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.events.EventType;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.events.MapAuthEventEntity;
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_AUTH_EVENT;
@ -53,7 +52,6 @@ import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSI
*/
@Entity
@Table(name = "kc_auth_event")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaAuthEventEntity extends MapAuthEventEntity.AbstractAuthEventEntity implements JpaRootVersionedEntity {
@Id
@ -65,7 +63,7 @@ public class JpaAuthEventEntity extends MapAuthEventEntity.AbstractAuthEventEnti
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaAuthEventMetadata metadata;

View file

@ -35,15 +35,14 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.group.MapGroupEntity.AbstractGroupEntity;
import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_GROUP;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
/**
* There are some fields marked by {@code @Column(insertable = false, updatable = false)}.
@ -52,7 +51,6 @@ import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
*/
@Entity
@Table(name = "kc_group", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "name", "parentId"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaGroupEntity extends AbstractGroupEntity implements JpaRootVersionedEntity {
@Id
@ -64,7 +62,7 @@ public class JpaGroupEntity extends AbstractGroupEntity implements JpaRootVersio
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaGroupMetadata metadata;

View file

@ -17,16 +17,16 @@
package org.keycloak.models.map.storage.jpa.hibernate.dialect;
import org.hibernate.dialect.PostgreSQL95Dialect;
import org.hibernate.dialect.function.SQLFunctionTemplate;
//import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.type.StandardBasicTypes;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
public class JsonbPostgreSQL95Dialect extends PostgreSQL95Dialect {
public JsonbPostgreSQL95Dialect() {
super();
registerFunction("->", new SQLFunctionTemplate(JsonbType.INSTANCE, "?1->?2"));
registerFunction("->>", new SQLFunctionTemplate(StandardBasicTypes.STRING, "?1->>?2"));
registerFunction("@>", new SQLFunctionTemplate(StandardBasicTypes.BOOLEAN, "?1@>?2::jsonb"));
registerFunction("kc_hash", new SQLFunctionTemplate(StandardBasicTypes.BINARY, "sha256(?1::bytea)"));
// registerFunction("->", new SQLFunctionTemplate(JsonbType.INSTANCE, "?1->?2"));
// registerFunction("->>", new SQLFunctionTemplate(StandardBasicTypes.STRING, "?1->>?2"));
// registerFunction("@>", new SQLFunctionTemplate(StandardBasicTypes.BOOLEAN, "?1@>?2::jsonb"));
// registerFunction("kc_hash", new SQLFunctionTemplate(StandardBasicTypes.BINARY, "sha256(?1::bytea)"));
}
}

View file

@ -44,12 +44,12 @@ import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.AbstractTypeDescriptor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.AbstractJavaType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.MutableMutabilityPlan;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.BasicBinder;
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.usertype.DynamicParameterizedType;
import org.keycloak.models.map.client.MapProtocolMapperEntity;
import org.keycloak.models.map.client.MapProtocolMapperEntityImpl;
@ -142,41 +142,36 @@ public class JsonbType extends AbstractSingleColumnStandardBasicType<Object> imp
return "jsonb";
}
private static class JsonbSqlTypeDescriptor implements SqlTypeDescriptor {
private static class JsonbSqlTypeDescriptor implements JdbcType {
private static final JsonbSqlTypeDescriptor INSTANCE = new JsonbSqlTypeDescriptor();
@Override
public int getSqlType() {
public int getJdbcTypeCode() {
return Types.OTHER;
}
@Override
public boolean canBeRemapped() {
return true;
}
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
public <X> ValueBinder<X> getBinder(JavaType<X> javaTypeDescriptor) {
return new BasicBinder<X>(javaTypeDescriptor, this) {
@Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getJdbcTypeCode());
}
@Override
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
st.setObject(name, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getJdbcTypeCode());
}
};
}
@Override
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaTypeDescriptor) {
return new BasicExtractor<X>(javaTypeDescriptor, this) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap(extractJson(rs, name), options);
protected X doExtract(ResultSet rs, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap(extractJson(rs, index), options);
}
@Override
@ -191,8 +186,8 @@ public class JsonbType extends AbstractSingleColumnStandardBasicType<Object> imp
};
}
private Object extractJson(ResultSet rs, String name) throws SQLException {
return rs.getObject(name);
private Object extractJson(ResultSet rs, int index) throws SQLException {
return rs.getObject(index);
}
private Object extractJson(CallableStatement statement, int index) throws SQLException {
@ -204,7 +199,7 @@ public class JsonbType extends AbstractSingleColumnStandardBasicType<Object> imp
}
}
private static class JsonbJavaTypeDescriptor extends AbstractTypeDescriptor<Object> implements DynamicParameterizedType {
private static class JsonbJavaTypeDescriptor extends AbstractJavaType<Object> implements DynamicParameterizedType {
private Class valueType;
@ -228,9 +223,9 @@ public class JsonbType extends AbstractSingleColumnStandardBasicType<Object> imp
@Override
@SuppressWarnings("unchecked")
public Object fromString(String json) {
public Object fromString(CharSequence json) {
try {
ObjectNode tree = MAPPER.readValue(json, ObjectNode.class);
ObjectNode tree = MAPPER.readValue(json.toString(), ObjectNode.class);
JsonNode ev = tree.get("entityVersion");
if (ev == null || ! ev.isInt()) throw new IllegalArgumentException("unable to read entity version from " + json);

View file

@ -97,7 +97,8 @@ public class JpaAutoFlushListener extends DefaultAutoFlushEventListener {
private boolean flushMightBeNeeded(final EventSource source) {
return !source.getHibernateFlushMode().lessThan(FlushMode.AUTO)
&& source.getDontFlushFromFind() == 0
// getDontFLushFromFind removed in hibernate 6s
// && source.getDontFlushFromFind() == 0
&& (source.getPersistenceContext().getNumberOfManagedEntities() > 0 ||
source.getPersistenceContext().getCollectionEntriesSize() > 0);
}

View file

@ -28,14 +28,13 @@ import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.loginFailure.MapUserLoginFailureEntity;
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_USER_LOGIN_FAILURE;
@ -52,7 +51,6 @@ import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSI
columnNames = {"realmId", "userId"}
)
})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaUserLoginFailureEntity extends MapUserLoginFailureEntity.AbstractUserLoginFailureEntity implements JpaRootVersionedEntity {
@Id
@ -64,7 +62,7 @@ public class JpaUserLoginFailureEntity extends MapUserLoginFailureEntity.Abstrac
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaUserLoginFailureMetadata metadata;

View file

@ -31,9 +31,9 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UpdatableEntity;
import org.keycloak.models.map.common.UuidValidator;
@ -41,7 +41,6 @@ import org.keycloak.models.map.realm.entity.MapComponentEntity;
import org.keycloak.models.map.storage.jpa.Constants;
import org.keycloak.models.map.storage.jpa.JpaChildEntity;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
/**
@ -59,7 +58,6 @@ import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
*/
@Entity
@Table(name = "kc_component")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaComponentEntity extends UpdatableEntity.Impl implements MapComponentEntity, JpaRootVersionedEntity, JpaChildEntity<JpaRealmEntity> {
@Id
@ -79,7 +77,7 @@ public class JpaComponentEntity extends UpdatableEntity.Impl implements MapCompo
@Basic(fetch = FetchType.LAZY)
private String providerType;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaComponentMetadata metadata;

View file

@ -38,9 +38,9 @@ import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.realm.MapRealmEntity;
@ -57,7 +57,6 @@ 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.JpaMapStorageProviderFactory.CLONER;
@ -74,7 +73,6 @@ import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.C
columnNames = {"name"}
)
})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
@SuppressWarnings("ConstantConditions")
public class JpaRealmEntity extends MapRealmEntity.AbstractRealmEntity implements JpaRootVersionedEntity {
@ -87,7 +85,7 @@ public class JpaRealmEntity extends MapRealmEntity.AbstractRealmEntity implement
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaRealmMetadata metadata;

View file

@ -35,15 +35,14 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.role.MapRoleEntity.AbstractRoleEntity;
import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSION_ROLE;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
/**
* There are some fields marked by {@code @Column(insertable = false, updatable = false)}.
@ -52,7 +51,6 @@ import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
*/
@Entity
@Table(name = "kc_role", uniqueConstraints = {@UniqueConstraint(columnNames = {"realmId", "clientId", "name"})})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaRoleEntity extends AbstractRoleEntity implements JpaRootVersionedEntity {
@Id
@ -64,7 +62,7 @@ public class JpaRoleEntity extends AbstractRoleEntity implements JpaRootVersione
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaRoleMetadata metadata;

View file

@ -33,14 +33,13 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UuidValidator;
import org.keycloak.models.map.singleUseObject.MapSingleUseObjectEntity;
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_SINGLE_USE_OBJECT;
@ -52,7 +51,6 @@ import static org.keycloak.models.map.storage.jpa.Constants.CURRENT_SCHEMA_VERSI
*/
@Entity
@Table(name = "kc_single_use_obj")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaSingleUseObjectEntity extends MapSingleUseObjectEntity.AbstractSingleUseObjectEntity implements JpaRootVersionedEntity {
@Id
@ -64,7 +62,7 @@ public class JpaSingleUseObjectEntity extends MapSingleUseObjectEntity.AbstractS
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaSingleUseObjectMetadata metadata;

View file

@ -31,15 +31,14 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UpdatableEntity;
import org.keycloak.models.map.storage.jpa.Constants;
import org.keycloak.models.map.storage.jpa.JpaChildEntity;
import org.keycloak.models.map.storage.jpa.JpaRootEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
import org.keycloak.models.map.user.MapUserConsentEntity;
/**
@ -53,7 +52,6 @@ import org.keycloak.models.map.user.MapUserConsentEntity;
uniqueConstraints = {
@UniqueConstraint(columnNames = {"clientId"})
})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaUserConsentEntity extends UpdatableEntity.Impl implements MapUserConsentEntity, JpaRootEntity, JpaChildEntity<JpaUserEntity> {
@Id
@ -69,7 +67,7 @@ public class JpaUserConsentEntity extends UpdatableEntity.Impl implements MapUse
@Basic(fetch = FetchType.LAZY)
private Integer entityVersion;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaUserConsentMetadata metadata;

View file

@ -40,14 +40,13 @@ import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
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;
import org.keycloak.models.map.user.MapUserCredentialEntity;
import org.keycloak.models.map.user.MapUserEntity;
@ -70,7 +69,6 @@ import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.C
@UniqueConstraint(columnNames = {"realmId", "username", "usernameWithCase"}),
@UniqueConstraint(columnNames = {"realmId", "emailConstraint"})
})
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
@SuppressWarnings("ConstantConditions")
public class JpaUserEntity extends MapUserEntity.AbstractUserEntity implements JpaRootVersionedEntity {
@ -83,7 +81,7 @@ public class JpaUserEntity extends MapUserEntity.AbstractUserEntity implements J
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaUserMetadata metadata;

View file

@ -29,15 +29,14 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UpdatableEntity;
import org.keycloak.models.map.storage.jpa.Constants;
import org.keycloak.models.map.storage.jpa.JpaChildEntity;
import org.keycloak.models.map.storage.jpa.JpaRootEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
import org.keycloak.models.map.user.MapUserFederatedIdentityEntity;
/**
@ -48,7 +47,6 @@ import org.keycloak.models.map.user.MapUserFederatedIdentityEntity;
*/
@Entity
@Table(name = "kc_user_federated_identity")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaUserFederatedIdentityEntity extends UpdatableEntity.Impl implements MapUserFederatedIdentityEntity, JpaRootEntity, JpaChildEntity<JpaUserEntity> {
@Id
@ -68,7 +66,7 @@ public class JpaUserFederatedIdentityEntity extends UpdatableEntity.Impl impleme
@Basic(fetch = FetchType.LAZY)
private String userId;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaUserFederatedIdentityMetadata metadata;

View file

@ -33,15 +33,14 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
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.JpaChildEntity;
import org.keycloak.models.map.storage.jpa.JpaRootVersionedEntity;
import org.keycloak.models.map.storage.jpa.hibernate.jsonb.JsonbType;
import org.keycloak.models.map.userSession.MapAuthenticatedClientSessionEntity.AbstractAuthenticatedClientSessionEntity;
/**
@ -49,7 +48,6 @@ import org.keycloak.models.map.userSession.MapAuthenticatedClientSessionEntity.A
*/
@Entity
@Table(name = "kc_client_session")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaClientSessionEntity extends AbstractAuthenticatedClientSessionEntity implements JpaRootVersionedEntity, JpaChildEntity<JpaUserSessionEntity> {
@Id
@ -61,7 +59,7 @@ public class JpaClientSessionEntity extends AbstractAuthenticatedClientSessionEn
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaClientSessionMetadata metadata;

View file

@ -33,15 +33,14 @@ import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.usertype.UserTypeLegacyBridge;
import org.keycloak.models.UserSessionModel;
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.userSession.MapAuthenticatedClientSessionEntity;
import org.keycloak.models.map.userSession.MapUserSessionEntity.AbstractUserSessionEntity;
@ -54,7 +53,6 @@ import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.C
*/
@Entity
@Table(name = "kc_user_session")
@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonbType.class)})
public class JpaUserSessionEntity extends AbstractUserSessionEntity implements JpaRootVersionedEntity {
@Id
@ -66,7 +64,7 @@ public class JpaUserSessionEntity extends AbstractUserSessionEntity implements J
@Column
private int version;
@Type(type = "jsonb")
@Type(value = UserTypeLegacyBridge.class, parameters = @Parameter(name = UserTypeLegacyBridge.TYPE_NAME_PARAM_KEY, value = "jsonb"))
@Column(columnDefinition = "jsonb")
private final JpaUserSessionMetadata metadata;

26
pom.xml
View file

@ -45,9 +45,9 @@
<project.build-time>${timestamp}</project.build-time>
<wildfly.version>26.1.1.Final</wildfly.version>
<wildfly.version>27.0.1.Final</wildfly.version>
<wildfly.build-tools.version>1.2.13.Final</wildfly.build-tools.version>
<wildfly.core.version>18.1.1.Final</wildfly.core.version>
<wildfly.core.version>19.0.1.Final</wildfly.core.version>
<wildfly.jakarta.adapters>true</wildfly.jakarta.adapters>
<apache.httpcomponents.fuse.version>4.5.2</apache.httpcomponents.fuse.version>
<apache.httpcomponents.httpcore.fuse.version>4.4.4</apache.httpcomponents.httpcore.fuse.version>
@ -79,7 +79,7 @@
<h2.version>2.1.214</h2.version>
<jakarta.persistence.version>2.2.3</jakarta.persistence.version>
<jakarta.servlet.jakarta-servlet-api.version>6.0.0</jakarta.servlet.jakarta-servlet-api.version>
<hibernate-orm.version>5.6.14.Final</hibernate-orm.version>
<hibernate-orm.version>6.1.6.Final</hibernate-orm.version>
<hibernate.c3p0.version>${hibernate-orm.version}</hibernate.c3p0.version>
<infinispan.version>14.0.7.Final</infinispan.version>
<infinispan.protostream.processor.version>4.6.0.Final</infinispan.protostream.processor.version>
@ -90,6 +90,7 @@
<!--JAKARTA-->
<jakarta.persistence.version>3.1.0</jakarta.persistence.version>
<jakarta.mail.version>2.1.0</jakarta.mail.version>
<jakarta.servlet.version>6.0.0</jakarta.servlet.version>
<jakarta.ws.rs.version>3.1.0</jakarta.ws.rs.version>
<jakarta.xml.ws.version>4.0.0</jakarta.xml.ws.version>
<jakarta.xml.bind.version>4.0.0</jakarta.xml.bind.version>
@ -111,13 +112,14 @@
<sun.xml.bind.version>2.3.3-b02</sun.xml.bind.version>
<javax.xml.bind.jaxb.version>2.4.0-b180830.0359</javax.xml.bind.jaxb.version>
<sun.xml.ws.version>2.3.1</sun.xml.ws.version>
<sun.activation.version>1.2.2</sun.activation.version>
<org.glassfish.jaxb.xsom.version>2.3.3-b02</org.glassfish.jaxb.xsom.version>
<undertow.version>2.2.19.Final</undertow.version>
<wildfly-elytron.version>1.20.3.Final</wildfly-elytron.version>
<elytron.undertow-server.version>1.9.0.Final</elytron.undertow-server.version>
<jetty94.version>9.4.40.v20210413</jetty94.version>
<woodstox.version>6.0.3</woodstox.version>
<xmlsec.version>3.0.1</xmlsec.version>
<xmlsec.version>2.2.3</xmlsec.version>
<wildfly.common.version>1.6.0.Final</wildfly.common.version>
<nashorn.version>15.4</nashorn.version>
<ua-parser.version>1.5.4</ua-parser.version>
@ -614,12 +616,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-orm.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate.c3p0.version}</version>
<scope>test</scope>
@ -889,7 +891,7 @@
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-core-feature-pack-ee-8-api</artifactId>
<artifactId>wildfly-core-feature-pack-ee-9-api</artifactId>
<type>pom</type>
<version>${wildfly.core.version}</version>
</dependency>
@ -964,6 +966,11 @@
<artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
<version>${infinispan.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-cachestore-remote</artifactId>
@ -1187,6 +1194,11 @@
<artifactId>keycloak-admin-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client-jakarta</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-as7-adapter</artifactId>