HHH-16391 - Incorrect mutability-plan resolution for converted collection-as-basic mappings

This commit is contained in:
Steve Ebersole 2023-03-28 16:28:04 -05:00
parent 03ee5445f8
commit f2be305a43
3 changed files with 16 additions and 2 deletions

View File

@ -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<J> implements BasicValue.Resolution<J> {
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();

View File

@ -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<List<S
if ( dbData == null ) {
return null;
}
return Arrays.asList( dbData.split( "," ) );
return listOf( dbData.split( "," ) );
}
}
//end::ex-csv-converter[]

View File

@ -63,6 +63,13 @@ public class CommaDelimitedStringsConverterTests {
final Person loaded = session.byId( Person.class ).load( 1 );
assertThat( loaded.nickNames ).hasSize( 2 );
assertThat( loaded.nickNames ).containsExactly( "John Q. Public", "Joe Public" );
loaded.nickNames.add( "Another one" );
} );
scope.inTransaction( (session) -> {
final Person reloaded = session.byId( Person.class ).load( 1 );
assertThat( reloaded.nickNames ).hasSize( 3 );
} );
}