From 9a5652ba7be55d66d816cfd467b1e45afc4fb8dd Mon Sep 17 00:00:00 2001 From: Cedomir Igaly Date: Thu, 8 Jun 2023 14:14:03 +0200 Subject: [PATCH] HHH-16759 - ComponentType.isMutable should return false when component is record; replace method(s) should return original for immutable classes --- .../main/java/org/hibernate/type/ComponentType.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 b9b7e2241a..7ca3588bd3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java @@ -26,6 +26,7 @@ import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.Generator; +import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Component; @@ -49,6 +50,7 @@ import org.hibernate.usertype.CompositeUserType; */ public class ComponentType extends AbstractType implements CompositeTypeImplementor, ProcedureParameterExtractionAware { private final Class componentClass; + private final boolean mutable; private final String[] propertyNames; private final Type[] propertyTypes; @@ -112,6 +114,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen else { this.compositeUserType = null; } + this.mutable = !ReflectHelper.isRecord( componentClass ) && ( compositeUserType == null || compositeUserType.isMutable() ); } private boolean isAggregate() { @@ -527,6 +530,9 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen Object owner, Map copyCache) { + if ( !isMutable() ) { + return original; + } if ( original == null ) { return null; } @@ -575,6 +581,9 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen Map copyCache, ForeignKeyDirection foreignKeyDirection) { + if ( !isMutable() ) { + return original; + } if ( original == null ) { return null; } @@ -623,7 +632,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen @Override public boolean isMutable() { - return compositeUserType == null || compositeUserType.isMutable(); + return mutable; } @Override