From f2be305a43deba50e5be308bace0be9918d467c5 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 28 Mar 2023 16:28:04 -0500 Subject: [PATCH] HHH-16391 - Incorrect mutability-plan resolution for converted collection-as-basic mappings --- .../model/process/internal/NamedConverterResolution.java | 4 +++- .../asbasic/CommaDelimitedStringsConverter.java | 7 ++++++- .../asbasic/CommaDelimitedStringsConverterTests.java | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java index 66d8b6ab60..3eff73136f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java @@ -6,6 +6,7 @@ */ package org.hibernate.boot.model.process.internal; +import java.util.Collection; import java.util.Map; import java.util.function.Function; @@ -16,7 +17,6 @@ import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Collection; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.converter.internal.AttributeConverterMutabilityPlanImpl; @@ -149,6 +149,8 @@ public class NamedConverterResolution implements BasicValue.Resolution { return ImmutableMutabilityPlan.instance(); } + // if the domain JavaType is immutable, use the immutability plan + // - note : ignore this for collection-as-basic mappings. if ( !domainJtd.getMutabilityPlan().isMutable() && !isCollection( domainJtd.getJavaTypeClass() ) ) { return ImmutableMutabilityPlan.instance(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/asbasic/CommaDelimitedStringsConverter.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/asbasic/CommaDelimitedStringsConverter.java index 931690191f..cf9cf982f2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/asbasic/CommaDelimitedStringsConverter.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/asbasic/CommaDelimitedStringsConverter.java @@ -6,12 +6,17 @@ */ package org.hibernate.orm.test.mapping.collections.asbasic; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.hibernate.internal.util.collections.CollectionHelper; + import jakarta.persistence.AttributeConverter; + import static org.hibernate.internal.util.StringHelper.join; +import static org.hibernate.internal.util.collections.CollectionHelper.listOf; /** * @author Steve Ebersole @@ -31,7 +36,7 @@ public class CommaDelimitedStringsConverter implements AttributeConverter { + final Person reloaded = session.byId( Person.class ).load( 1 ); + assertThat( reloaded.nickNames ).hasSize( 3 ); } ); }