From 893e1b096e714d7a0fbccc2d4137817a566fb3f5 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 14 Sep 2022 15:03:51 +0200 Subject: [PATCH] HHH-15500 Cache key is huge since migration to 6 --- .../internal/CacheKeyImplementation.java | 30 ++++++++++++++---- .../ComponentCacheKeyValueDescriptor.java | 15 ++++++--- ...ustomComponentCacheKeyValueDescriptor.java | 11 +------ .../DefaultCacheKeyValueDescriptor.java | 23 ++++++++++++++ .../JavaTypeCacheKeyValueDescriptor.java | 28 +++++++++++++++++ .../internal/AbstractEmbeddableMapping.java | 6 ---- .../internal/EmbeddableMappingTypeImpl.java | 2 +- .../mapping/internal/IdClassEmbeddable.java | 4 +-- .../org/hibernate/type/ComponentType.java | 14 +++------ .../java/org/hibernate/type/CustomType.java | 31 +++++++++++++++++++ .../descriptor/java/BigDecimalJavaType.java | 7 +++++ .../descriptor/java/BigIntegerJavaType.java | 7 +++++ .../BigNumberCacheKeyValueDescriptor.java | 24 ++++++++++++++ .../type/descriptor/java/BooleanJavaType.java | 8 +++++ .../type/descriptor/java/ByteJavaType.java | 8 +++++ .../descriptor/java/CalendarDateJavaType.java | 19 ++++++++++++ .../descriptor/java/CalendarJavaType.java | 19 ++++++++++++ .../descriptor/java/CalendarTimeJavaType.java | 19 ++++++++++++ .../descriptor/java/CharacterJavaType.java | 8 +++++ .../type/descriptor/java/ClassJavaType.java | 9 ++++++ .../descriptor/java/CurrencyJavaType.java | 8 +++++ .../type/descriptor/java/DateJavaType.java | 19 ++++++++++++ .../descriptor/java/DbTimestampJavaType.java | 7 +++++ .../type/descriptor/java/DoubleJavaType.java | 8 +++++ .../type/descriptor/java/EnumJavaType.java | 8 +++++ .../type/descriptor/java/FloatJavaType.java | 8 +++++ .../descriptor/java/InetAddressJavaType.java | 8 +++++ .../type/descriptor/java/InstantJavaType.java | 8 +++++ .../type/descriptor/java/IntegerJavaType.java | 8 +++++ .../type/descriptor/java/JavaType.java | 12 +++++++ .../descriptor/java/JdbcDateJavaType.java | 19 ++++++++++++ .../descriptor/java/JdbcTimeJavaType.java | 19 ++++++++++++ .../java/JdbcTimestampJavaType.java | 19 ++++++++++++ .../descriptor/java/LocalDateJavaType.java | 8 +++++ .../java/LocalDateTimeJavaType.java | 8 +++++ .../descriptor/java/LocalTimeJavaType.java | 8 +++++ .../type/descriptor/java/LocaleJavaType.java | 8 +++++ .../type/descriptor/java/LongJavaType.java | 8 +++++ .../type/descriptor/java/ObjectJavaType.java | 8 +++++ .../java/OffsetDateTimeJavaType.java | 8 +++++ .../descriptor/java/OffsetTimeJavaType.java | 8 +++++ .../type/descriptor/java/ShortJavaType.java | 8 +++++ .../type/descriptor/java/StringJavaType.java | 8 +++++ .../descriptor/java/TimeZoneJavaType.java | 8 +++++ .../type/descriptor/java/UUIDJavaType.java | 8 +++++ .../type/descriptor/java/UrlJavaType.java | 8 +++++ .../type/descriptor/java/YearJavaType.java | 8 +++++ .../type/descriptor/java/ZoneIdJavaType.java | 8 +++++ .../java/ZonedDateTimeJavaType.java | 8 +++++ .../java/spi/JavaTypeBasicAdaptor.java | 8 +++++ .../type/internal/BasicTypeImpl.java | 13 ++++++++ .../type/internal/ConvertedBasicTypeImpl.java | 13 +++++++- 52 files changed, 565 insertions(+), 40 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeyValueDescriptor.java create mode 100644 hibernate-core/src/main/java/org/hibernate/cache/internal/JavaTypeCacheKeyValueDescriptor.java create mode 100644 hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigNumberCacheKeyValueDescriptor.java diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java index bf7e747b06..9c202ae23d 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java @@ -50,10 +50,19 @@ public final class CacheKeyImplementation implements Serializable { final String tenantId, final SessionFactoryImplementor factory) { this.id = id; - this.cacheKeyValueDescriptor = type.toCacheKeyDescriptor( factory ); this.entityOrRoleName = entityOrRoleName; this.tenantId = tenantId; - this.hashCode = calculateHashCode( ); + final CacheKeyValueDescriptor cacheKeyValueDescriptor = type.toCacheKeyDescriptor( factory ); + // Optimization for the very common case Integer/Long etc. which use the default cache key descriptor + // Doing this helps to avoid megamorphic call sites and reduces the cache key serialization size + if ( cacheKeyValueDescriptor == DefaultCacheKeyValueDescriptor.INSTANCE ) { + this.cacheKeyValueDescriptor = null; + this.hashCode = Objects.hashCode( id ); + } + else { + this.cacheKeyValueDescriptor = cacheKeyValueDescriptor; + this.hashCode = calculateHashCode(); + } } private int calculateHashCode() { @@ -74,14 +83,23 @@ public final class CacheKeyImplementation implements Serializable { if ( this == other ) { return true; } - if ( hashCode != other.hashCode() || !( other instanceof CacheKeyImplementation) ) { + if ( hashCode != other.hashCode() || !( other instanceof CacheKeyImplementation ) ) { //hashCode is part of this check since it is pre-calculated and hash must match for equals to be true return false; } final CacheKeyImplementation that = (CacheKeyImplementation) other; - return Objects.equals( entityOrRoleName, that.entityOrRoleName ) - && cacheKeyValueDescriptor.isEqual( id, that.id ) - && Objects.equals( tenantId, that.tenantId ); + if ( !entityOrRoleName.equals( that.entityOrRoleName ) ) { + return false; + } + if ( cacheKeyValueDescriptor == null ) { + if ( !Objects.equals( id, that.id ) ) { + return false; + } + } + else if ( !cacheKeyValueDescriptor.isEqual( id, that.id ) ) { + return false; + } + return Objects.equals( tenantId, that.tenantId ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/ComponentCacheKeyValueDescriptor.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/ComponentCacheKeyValueDescriptor.java index 3df39b87d6..6796dc8d01 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/ComponentCacheKeyValueDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/ComponentCacheKeyValueDescriptor.java @@ -20,14 +20,17 @@ import org.hibernate.type.descriptor.java.JavaType; * @see CustomComponentCacheKeyValueDescriptor */ public class ComponentCacheKeyValueDescriptor implements CacheKeyValueDescriptor { - private final NavigableRole role; + private final String role; private final SessionFactoryImplementor sessionFactory; private transient EmbeddableValuedModelPart embeddedMapping; - public ComponentCacheKeyValueDescriptor(NavigableRole role, SessionFactoryImplementor sessionFactory) { - this.role = role; + public ComponentCacheKeyValueDescriptor( + EmbeddableValuedModelPart embeddedMapping, + SessionFactoryImplementor sessionFactory) { + this.role = embeddedMapping.getNavigableRole().getFullPath(); this.sessionFactory = sessionFactory; + this.embeddedMapping = embeddedMapping; } @Override @@ -82,10 +85,12 @@ public class ComponentCacheKeyValueDescriptor implements CacheKeyValueDescriptor } } - private EmbeddableValuedModelPart getEmbeddedMapping() { + EmbeddableValuedModelPart embeddedMapping = this.embeddedMapping; if ( embeddedMapping == null ) { - embeddedMapping = sessionFactory.getRuntimeMetamodels().getEmbedded( role ); + this.embeddedMapping = embeddedMapping = sessionFactory.getRuntimeMetamodels().getEmbedded( + new NavigableRole( role ) + ); } return embeddedMapping; } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/CustomComponentCacheKeyValueDescriptor.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/CustomComponentCacheKeyValueDescriptor.java index 9b5ab640e9..d934db631a 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/CustomComponentCacheKeyValueDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/CustomComponentCacheKeyValueDescriptor.java @@ -6,20 +6,15 @@ */ package org.hibernate.cache.internal; -import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.usertype.CompositeUserType; /** * CacheKeyValueDescriptor used to describe CompositeUserType mappings */ public class CustomComponentCacheKeyValueDescriptor implements CacheKeyValueDescriptor { - private final NavigableRole role; private final CompositeUserType compositeUserType; - public CustomComponentCacheKeyValueDescriptor( - NavigableRole role, - CompositeUserType compositeUserType) { - this.role = role; + public CustomComponentCacheKeyValueDescriptor(CompositeUserType compositeUserType) { this.compositeUserType = compositeUserType; } @@ -33,8 +28,4 @@ public class CustomComponentCacheKeyValueDescriptor implements CacheKeyValueDesc return compositeUserType.equals( key1, key2 ); } - @Override - public String toString() { - return "CustomComponentCacheKeyValueDescriptor(" + role + ")"; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeyValueDescriptor.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeyValueDescriptor.java new file mode 100644 index 0000000000..2d8b713e37 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeyValueDescriptor.java @@ -0,0 +1,23 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.cache.internal; + +import java.util.Objects; + +public class DefaultCacheKeyValueDescriptor implements CacheKeyValueDescriptor { + public static final DefaultCacheKeyValueDescriptor INSTANCE = new DefaultCacheKeyValueDescriptor(); + + @Override + public int getHashCode(Object key) { + return key.hashCode(); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return Objects.equals( key1, key2 ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/JavaTypeCacheKeyValueDescriptor.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/JavaTypeCacheKeyValueDescriptor.java new file mode 100644 index 0000000000..9c9bedf70a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/JavaTypeCacheKeyValueDescriptor.java @@ -0,0 +1,28 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.cache.internal; + +import org.hibernate.type.descriptor.java.JavaType; + +public class JavaTypeCacheKeyValueDescriptor implements CacheKeyValueDescriptor { + private final JavaType javaType; + + public JavaTypeCacheKeyValueDescriptor(JavaType javaType) { + //noinspection unchecked + this.javaType = (JavaType) javaType; + } + + @Override + public int getHashCode(Object key) { + return javaType.extractHashCode( key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return javaType.areEqual( key1, key2 ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java index bee1e9756a..7871b25b5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java @@ -60,18 +60,12 @@ import org.hibernate.type.spi.TypeConfiguration; * Base support for EmbeddableMappingType implementations */ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType { - protected final SessionFactoryImplementor sessionFactory; public AbstractEmbeddableMapping(MappingModelCreationProcess creationProcess) { this( creationProcess.getCreationContext() ); } public AbstractEmbeddableMapping(RuntimeModelCreationContext creationContext) { - this( creationContext.getSessionFactory() ); - } - - protected AbstractEmbeddableMapping(SessionFactoryImplementor sessionFactory) { - this.sessionFactory = sessionFactory; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index 35b51a4f4c..648681fd3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -143,7 +143,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme this.embeddableJtd = representationStrategy.getMappedJavaType(); this.valueMapping = embeddedPartBuilder.apply( this ); - final ConfigurationService cs = sessionFactory.getServiceRegistry() + final ConfigurationService cs = creationContext.getSessionFactory().getServiceRegistry() .getService(ConfigurationService.class); this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java index 0fbf05b1d9..8a9494a744 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/IdClassEmbeddable.java @@ -84,7 +84,7 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden this.idMapping = idMapping; this.virtualIdEmbeddable = virtualIdEmbeddable; - this.javaType = sessionFactory.getTypeConfiguration() + this.javaType = creationProcess.getCreationContext().getSessionFactory().getTypeConfiguration() .getJavaTypeRegistry() .resolveManagedTypeDescriptor( idClassSource.getComponentClass() ); @@ -176,7 +176,7 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden public Object getIdentifier(Object entity, SharedSessionContractImplementor session) { final Object id = representationStrategy.getInstantiator().instantiate( null, - sessionFactory + session.getSessionFactory() ); final List virtualIdAttribute = virtualIdEmbeddable.getAttributeMappings(); diff --git a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java index c168fb4a48..96be55f232 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java @@ -67,7 +67,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen private final CompositeUserType compositeUserType; private EmbeddableValuedModelPart mappingModelPart; - private CacheKeyValueDescriptor cacheKeyValueDescriptor; + private transient CacheKeyValueDescriptor cacheKeyValueDescriptor; public ComponentType(Component component, int[] originalPropertyOrder, MetadataBuildingContext buildingContext) { this.componentClass = component.isDynamic() @@ -705,19 +705,15 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen @Override public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + CacheKeyValueDescriptor cacheKeyValueDescriptor = this.cacheKeyValueDescriptor; if ( cacheKeyValueDescriptor == null ) { if ( compositeUserType != null ) { - cacheKeyValueDescriptor = new CustomComponentCacheKeyValueDescriptor( - mappingModelPart.getNavigableRole(), - compositeUserType - ); + cacheKeyValueDescriptor = new CustomComponentCacheKeyValueDescriptor( compositeUserType ); } else { - cacheKeyValueDescriptor = new ComponentCacheKeyValueDescriptor( - mappingModelPart.getNavigableRole(), - sessionFactory - ); + cacheKeyValueDescriptor = new ComponentCacheKeyValueDescriptor( mappingModelPart, sessionFactory ); } + this.cacheKeyValueDescriptor = cacheKeyValueDescriptor; } return cacheKeyValueDescriptor; diff --git a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java index d7f05ffd7c..d4bb9a1298 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CustomType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CustomType.java @@ -15,6 +15,7 @@ import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.MappingException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -66,6 +67,8 @@ public class CustomType private final ValueBinder valueBinder; private final JdbcLiteralFormatter jdbcLiteralFormatter; + private transient CacheKeyValueDescriptor cacheKeyValueDescriptor; + public CustomType(UserType userType, TypeConfiguration typeConfiguration) throws MappingException { this( userType, ArrayHelper.EMPTY_STRING_ARRAY, typeConfiguration ); } @@ -388,4 +391,32 @@ public class CustomType public BasicValueConverter getValueConverter() { return userType.getValueConverter(); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + CacheKeyValueDescriptor cacheKeyValueDescriptor = this.cacheKeyValueDescriptor; + if ( cacheKeyValueDescriptor == null ) { + this.cacheKeyValueDescriptor = cacheKeyValueDescriptor = new CustomTypeCacheKeyValueDescriptor( getUserType() ); + } + return cacheKeyValueDescriptor; + } + + private static final class CustomTypeCacheKeyValueDescriptor implements CacheKeyValueDescriptor { + private final UserType userType; + + public CustomTypeCacheKeyValueDescriptor(UserType userType) { + //noinspection unchecked + this.userType = (UserType) userType; + } + + @Override + public int getHashCode(Object key) { + return userType.hashCode( key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return userType.equals( key1, key2 ); + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java index eb2049f730..5d9891214c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java @@ -10,7 +10,9 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -44,6 +46,11 @@ public class BigDecimalJavaType extends AbstractClassJavaType { return value.intValue(); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return BigNumberCacheKeyValueDescriptor.INSTANCE; + } + @SuppressWarnings("unchecked") public X unwrap(BigDecimal value, Class type, WrapperOptions options) { if ( value == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java index 8b85515dd1..d8b9384cbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java @@ -10,7 +10,9 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -46,6 +48,11 @@ public class BigIntegerJavaType extends AbstractClassJavaType { return one == another || ( one != null && another != null && one.compareTo( another ) == 0 ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return BigNumberCacheKeyValueDescriptor.INSTANCE; + } + @Override @SuppressWarnings("unchecked") public X unwrap(BigInteger value, Class type, WrapperOptions options) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigNumberCacheKeyValueDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigNumberCacheKeyValueDescriptor.java new file mode 100644 index 0000000000..5e3696a849 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigNumberCacheKeyValueDescriptor.java @@ -0,0 +1,24 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.type.descriptor.java; + +import org.hibernate.cache.internal.CacheKeyValueDescriptor; + +final class BigNumberCacheKeyValueDescriptor implements CacheKeyValueDescriptor { + static final BigNumberCacheKeyValueDescriptor INSTANCE = new BigNumberCacheKeyValueDescriptor(); + + @Override + public int getHashCode(Object key) { + return ( (Number) key ).intValue(); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + //noinspection unchecked + return ( key1 == key2 ) || ( key1 != null && key2 != null && ( (Comparable) key1 ).compareTo( key2 ) == 0 ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java index 7bb09668e3..a540210b0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java @@ -6,7 +6,10 @@ */ package org.hibernate.type.descriptor.java; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -177,4 +180,9 @@ public class BooleanJavaType extends AbstractClassJavaType implements ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java index 947692e950..a91d2d7903 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteJavaType.java @@ -9,7 +9,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; @@ -191,4 +194,9 @@ public class ByteJavaType extends AbstractClassJavaType Integer precision, Integer scale, SharedSessionContractImplementor session) { return ZERO; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java index 4f71074e6b..819f5dd233 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java @@ -13,7 +13,9 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.compare.CalendarComparator; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -28,6 +30,18 @@ import org.hibernate.type.spi.TypeConfiguration; public class CalendarDateJavaType extends AbstractTemporalJavaType { public static final CalendarDateJavaType INSTANCE = new CalendarDateJavaType(); + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Calendar) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Calendar) key1, (Calendar) key2 ); + } + }; + protected CalendarDateJavaType() { super( Calendar.class, CalendarJavaType.CalendarMutabilityPlan.INSTANCE, CalendarComparator.INSTANCE ); } @@ -93,6 +107,11 @@ public class CalendarDateJavaType extends AbstractTemporalJavaType { return hashCode; } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @SuppressWarnings("unchecked") public X unwrap(Calendar value, Class type, WrapperOptions options) { if ( value == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java index 1964f82289..94ce510f6e 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java @@ -14,7 +14,9 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.compare.CalendarComparator; import org.hibernate.type.descriptor.WrapperOptions; @@ -38,6 +40,18 @@ public class CalendarJavaType extends AbstractTemporalJavaType impleme } } + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Calendar) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Calendar) key1, (Calendar) key2 ); + } + }; + protected CalendarJavaType() { super( Calendar.class, CalendarMutabilityPlan.INSTANCE, CalendarComparator.INSTANCE ); } @@ -111,6 +125,11 @@ public class CalendarJavaType extends AbstractTemporalJavaType impleme return hashCode; } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @SuppressWarnings("unchecked") public X unwrap(Calendar value, Class type, WrapperOptions options) { if ( value == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java index 832b6965be..f1f39e05e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java @@ -13,7 +13,9 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.compare.CalendarComparator; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -28,6 +30,18 @@ import org.hibernate.type.spi.TypeConfiguration; public class CalendarTimeJavaType extends AbstractTemporalJavaType { public static final CalendarTimeJavaType INSTANCE = new CalendarTimeJavaType(); + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Calendar) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Calendar) key1, (Calendar) key2 ); + } + }; + protected CalendarTimeJavaType() { super( Calendar.class, CalendarJavaType.CalendarMutabilityPlan.INSTANCE, CalendarComparator.INSTANCE ); } @@ -93,6 +107,11 @@ public class CalendarTimeJavaType extends AbstractTemporalJavaType { return hashCode; } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @SuppressWarnings("unchecked") public X unwrap(Calendar value, Class type, WrapperOptions options) { if ( value == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterJavaType.java index 15041a34d5..502e739987 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterJavaType.java @@ -7,7 +7,10 @@ package org.hibernate.type.descriptor.java; import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -110,4 +113,9 @@ public class CharacterJavaType extends AbstractClassJavaType implemen public int getDefaultSqlScale(Dialect dialect, JdbcType jdbcType) { return 0; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClassJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClassJavaType.java index 5ea91057c4..43d76754fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClassJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClassJavaType.java @@ -5,7 +5,11 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.type.descriptor.java; + import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.type.descriptor.WrapperOptions; @@ -64,4 +68,9 @@ public class ClassJavaType extends AbstractClassJavaType { } throw unknownWrap( value.getClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyJavaType.java index 50ea82344e..7d92eb5b73 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CurrencyJavaType.java @@ -8,7 +8,10 @@ package org.hibernate.type.descriptor.java; import java.util.Currency; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -60,4 +63,9 @@ public class CurrencyJavaType extends AbstractClassJavaType { public long getDefaultSqlLength(Dialect dialect, JdbcType jdbcType) { return 3; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java index c279d42311..03f572128b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java @@ -17,7 +17,9 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -41,6 +43,18 @@ public class DateJavaType extends AbstractTemporalJavaType implements Vers } } + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Date) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Date) key1, (Date) key2 ); + } + }; + public DateJavaType() { super( Date.class, DateMutabilityPlan.INSTANCE ); } @@ -108,6 +122,11 @@ public class DateJavaType extends AbstractTemporalJavaType implements Vers return CalendarJavaType.INSTANCE.extractHashCode( calendar ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @SuppressWarnings("unchecked") @Override public X unwrap(Date value, Class type, WrapperOptions options) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DbTimestampJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DbTimestampJavaType.java index 32f46d73e4..fef8a79022 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DbTimestampJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DbTimestampJavaType.java @@ -14,7 +14,9 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.Comparator; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.type.descriptor.WrapperOptions; @@ -256,4 +258,9 @@ public class DbTimestampJavaType implements VersionJavaType, TemporalJavaT TypeConfiguration typeConfiguration) { return delegate.resolveTypeForPrecision( precision, typeConfiguration ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return delegate.toCacheKeyDescriptor( sessionFactory ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java index 5b0341749b..7287e686fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java @@ -10,7 +10,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; import org.hibernate.type.descriptor.jdbc.DoubleJdbcType; @@ -208,4 +211,9 @@ public class DoubleJavaType extends AbstractClassJavaType implements ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java index 76ec6e72e5..c41403de46 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java @@ -9,7 +9,10 @@ package org.hibernate.type.descriptor.java; import java.sql.Types; import jakarta.persistence.EnumType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -219,4 +222,9 @@ public class EnumJavaType> extends AbstractClassJavaType { public String getCheckCondition(String columnName, JdbcType jdbcType, Dialect dialect) { return dialect.getEnumCheckCondition( columnName, jdbcType.getJdbcTypeCode(), getJavaTypeClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java index c4f5c3d246..d885f5d1c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java @@ -10,7 +10,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; @@ -202,4 +205,9 @@ public class FloatJavaType extends AbstractClassJavaType implements Primi ) ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java index 6c881bf1a6..cdd508c358 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InetAddressJavaType.java @@ -9,7 +9,10 @@ package org.hibernate.type.descriptor.java; import java.net.InetAddress; import java.net.UnknownHostException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -98,4 +101,9 @@ public class InetAddressJavaType extends AbstractClassJavaType { return 19; } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java index 820ac05543..c09eff5070 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java @@ -19,7 +19,10 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; @@ -209,4 +212,9 @@ public class InstantJavaType extends AbstractTemporalJavaType return Instant.now( ClockHelper.forPrecision( precision, session ) ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java index 4bd179b5da..4218e0eb06 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java @@ -10,7 +10,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; @@ -209,4 +212,9 @@ public class IntegerJavaType extends AbstractClassJavaType return current + 1; } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java index 39e400bc91..ecef9adf39 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java @@ -12,9 +12,13 @@ import java.lang.reflect.Type; import java.util.Comparator; import java.util.Objects; +import org.hibernate.HibernateException; import org.hibernate.Incubating; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.JavaTypeCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.Size; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.compare.ComparableComparator; @@ -274,4 +278,12 @@ public interface JavaType extends Serializable { TypeConfiguration typeConfiguration) { return createJavaType( parameterizedType ); } + + default CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + if ( this instanceof CacheKeyValueDescriptor ) { + return (CacheKeyValueDescriptor) this; + } + + return new JavaTypeCacheKeyValueDescriptor( this ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java index de773a01a9..48d14c0780 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateJavaType.java @@ -16,6 +16,8 @@ import java.util.Date; import java.util.GregorianCalendar; import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; @@ -44,6 +46,18 @@ public class JdbcDateJavaType extends AbstractTemporalJavaType { @SuppressWarnings("unused") public static final DateTimeFormatter LITERAL_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE; + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Date) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Date) key1, (Date) key2 ); + } + }; + public JdbcDateJavaType() { super( java.sql.Date.class, DateMutabilityPlan.INSTANCE ); } @@ -95,6 +109,11 @@ public class JdbcDateJavaType extends AbstractTemporalJavaType { return hashCode; } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @Override public Date coerce(Object value, CoercionContext coercionContext) { return wrap( value, null ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java index 21af8d9621..ed2a9532e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeJavaType.java @@ -17,7 +17,9 @@ import java.util.Date; import java.util.GregorianCalendar; import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; @@ -50,6 +52,18 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType { @SuppressWarnings("unused") public static final DateTimeFormatter LOGGABLE_FORMATTER = DateTimeFormatter.ISO_LOCAL_TIME; + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Date) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Date) key1, (Date) key2 ); + } + }; + public JdbcTimeJavaType() { super( Time.class, TimeMutabilityPlan.INSTANCE ); } @@ -103,6 +117,11 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType { && calendar1.get( Calendar.MILLISECOND ) == calendar2.get( Calendar.MILLISECOND ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @Override public Date coerce(Object value, CoercionContext coercionContext) { return wrap( value, null ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java index 4493c94d54..131bd35f91 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java @@ -21,7 +21,9 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -50,6 +52,18 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType implem public static final DateTimeFormatter LITERAL_FORMATTER = DateTimeFormatter.ofPattern( TIMESTAMP_FORMAT ) .withZone( ZoneId.from( ZoneOffset.UTC ) ); + private static final CacheKeyValueDescriptor CACHE_KEY_VALUE_DESCRIPTOR = new CacheKeyValueDescriptor() { + @Override + public int getHashCode(Object key) { + return INSTANCE.extractHashCode( (Date) key ); + } + + @Override + public boolean isEqual(Object key1, Object key2) { + return INSTANCE.areEqual( (Date) key1, (Date) key2 ); + } + }; + public JdbcTimestampJavaType() { super( Timestamp.class, TimestampMutabilityPlan.INSTANCE ); } @@ -104,6 +118,11 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType implem return Long.valueOf( value.getTime() / 1000 ).hashCode(); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return CACHE_KEY_VALUE_DESCRIPTOR; + } + @Override public Date coerce(Object value, CoercionContext coercionContext) { return wrap( value, null ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java index 4513f9bd37..2a04639aac 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java @@ -20,6 +20,9 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; @@ -167,4 +170,9 @@ public class LocalDateJavaType extends AbstractTemporalJavaType { } } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java index bb14d62321..9b1b2578f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java @@ -18,7 +18,10 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -189,4 +192,9 @@ public class LocalDateTimeJavaType extends AbstractTemporalJavaType { public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) { return 0; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java index 9da9343a66..e181e14f8a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java @@ -9,6 +9,9 @@ package org.hibernate.type.descriptor.java; import java.util.Comparator; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; /** @@ -106,4 +109,9 @@ public class LocaleJavaType extends AbstractClassJavaType { } throw unknownWrap( value.getClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java index 1f75f87d7f..5eb34ecc42 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java @@ -10,7 +10,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; @@ -212,4 +215,9 @@ public class LongJavaType extends AbstractClassJavaType Integer precision, Integer scale, SharedSessionContractImplementor session) { return ZERO; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectJavaType.java index 23cb82c0fe..3844c9af03 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectJavaType.java @@ -6,6 +6,9 @@ */ package org.hibernate.type.descriptor.java; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; /** @@ -31,4 +34,9 @@ public class ObjectJavaType extends AbstractClassJavaType { public Object wrap(X value, WrapperOptions options) { return value; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java index 2b67e3256f..74586dea93 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java @@ -21,7 +21,10 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.TimeZoneStorageStrategy; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; @@ -239,4 +242,9 @@ public class OffsetDateTimeJavaType extends AbstractTemporalJavaType { public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) { return 0; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java index 9af5af62a7..752c24efc4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java @@ -9,7 +9,10 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.spi.PrimitiveJavaType; @@ -199,4 +202,9 @@ public class ShortJavaType extends AbstractClassJavaType SharedSessionContractImplementor session) { return (short) ( current + 1 ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java index bf8ea220de..6714139f4c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java @@ -11,8 +11,11 @@ import java.io.StringReader; import java.sql.Clob; import java.sql.Types; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.engine.jdbc.CharacterStream; import org.hibernate.engine.jdbc.internal.CharacterStreamImpl; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; @@ -112,4 +115,9 @@ public class StringJavaType extends AbstractClassJavaType { return false; } } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java index b5ce42ac12..a75eb5e653 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java @@ -9,6 +9,9 @@ package org.hibernate.type.descriptor.java; import java.util.Comparator; import java.util.TimeZone; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; /** @@ -59,4 +62,9 @@ public class TimeZoneJavaType extends AbstractClassJavaType { } throw unknownWrap( value.getClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UUIDJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UUIDJavaType.java index 59c9720a3c..a90222f20c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UUIDJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UUIDJavaType.java @@ -9,7 +9,10 @@ package org.hibernate.type.descriptor.java; import java.io.Serializable; import java.util.UUID; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.BytesHelper; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -155,4 +158,9 @@ public class UUIDJavaType extends AbstractClassJavaType { return new UUID( BytesHelper.asLong( bytea, 0 ), BytesHelper.asLong( bytea, 8 ) ); } } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java index 7ed878f1c1..4bcfa30808 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/UrlJavaType.java @@ -10,6 +10,9 @@ import java.net.MalformedURLException; import java.net.URL; import org.hibernate.HibernateException; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.SqlTypes; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; @@ -65,4 +68,9 @@ public class UrlJavaType extends AbstractClassJavaType { } throw unknownWrap( value.getClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/YearJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/YearJavaType.java index 5d8de30986..847fa966e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/YearJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/YearJavaType.java @@ -10,6 +10,9 @@ import java.sql.Types; import java.time.Year; import java.time.format.DateTimeFormatter; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; @@ -82,4 +85,9 @@ public class YearJavaType extends AbstractClassJavaType { throw unknownWrap( value.getClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneIdJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneIdJavaType.java index 0e80900fba..9bd49151ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneIdJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneIdJavaType.java @@ -9,6 +9,9 @@ package org.hibernate.type.descriptor.java; import java.sql.Types; import java.time.ZoneId; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; @@ -67,4 +70,9 @@ public class ZoneIdJavaType extends AbstractClassJavaType { throw unknownWrap( value.getClass() ); } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java index 4b4c01471b..0677b1d44b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java @@ -21,7 +21,10 @@ import java.util.GregorianCalendar; import jakarta.persistence.TemporalType; import org.hibernate.TimeZoneStorageStrategy; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.cache.internal.DefaultCacheKeyValueDescriptor; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.ZonedDateTimeComparator; import org.hibernate.type.SqlTypes; @@ -235,4 +238,9 @@ public class ZonedDateTimeJavaType extends AbstractTemporalJavaType extends AbstractClassJavaType { ); } + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + return DefaultCacheKeyValueDescriptor.INSTANCE; + } + @Override public String toString() { return "JavaTypeBasicAdaptor(" + getJavaType().getTypeName() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/BasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/internal/BasicTypeImpl.java index 973ea638b6..201eb57a0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/BasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/BasicTypeImpl.java @@ -8,6 +8,8 @@ package org.hibernate.type.internal; import java.util.Locale; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.type.AbstractSingleColumnStandardBasicType; import org.hibernate.type.AdjustableBasicType; @@ -25,6 +27,8 @@ public class BasicTypeImpl extends AbstractSingleColumnStandardBasicType i private final String name; + private transient CacheKeyValueDescriptor cacheKeyValueDescriptor; + public BasicTypeImpl(JavaType jtd, JdbcType std) { super( std, jtd ); name = String.format( @@ -70,4 +74,13 @@ public class BasicTypeImpl extends AbstractSingleColumnStandardBasicType i public String toString() { return name; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + CacheKeyValueDescriptor cacheKeyValueDescriptor = this.cacheKeyValueDescriptor; + if ( cacheKeyValueDescriptor == null ) { + this.cacheKeyValueDescriptor = cacheKeyValueDescriptor = getMappedJavaType().toCacheKeyDescriptor( sessionFactory ); + } + return cacheKeyValueDescriptor; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java index e5f1b271ad..e34e9c3c74 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/ConvertedBasicTypeImpl.java @@ -19,6 +19,7 @@ import org.hibernate.Hibernate; import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; +import org.hibernate.cache.internal.CacheKeyValueDescriptor; import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -34,7 +35,6 @@ import org.hibernate.type.TrueFalseConverter; import org.hibernate.type.YesNoConverter; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; -import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter; @@ -59,6 +59,8 @@ public class ConvertedBasicTypeImpl implements ConvertedBasicType, private final ValueExtractor jdbcValueExtractor; private final JdbcLiteralFormatter jdbcLiteralFormatter; + private transient CacheKeyValueDescriptor cacheKeyValueDescriptor; + public ConvertedBasicTypeImpl( String name, JdbcType jdbcType, @@ -416,4 +418,13 @@ public class ConvertedBasicTypeImpl implements ConvertedBasicType, public String toString() { return description; } + + @Override + public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) { + CacheKeyValueDescriptor cacheKeyValueDescriptor = this.cacheKeyValueDescriptor; + if ( cacheKeyValueDescriptor == null ) { + this.cacheKeyValueDescriptor = cacheKeyValueDescriptor = converter.getDomainJavaType().toCacheKeyDescriptor( sessionFactory ); + } + return cacheKeyValueDescriptor; + } }