HHH-16391 - Incorrect mutability-plan resolution for converted collection-as-basic mappings
This commit is contained in:
parent
03ee5445f8
commit
f2be305a43
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.boot.model.process.internal;
|
package org.hibernate.boot.model.process.internal;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
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.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||||
import org.hibernate.mapping.BasicValue;
|
import org.hibernate.mapping.BasicValue;
|
||||||
import org.hibernate.mapping.Collection;
|
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.descriptor.converter.internal.AttributeConverterMutabilityPlanImpl;
|
import org.hibernate.type.descriptor.converter.internal.AttributeConverterMutabilityPlanImpl;
|
||||||
|
@ -149,6 +149,8 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
|
||||||
return ImmutableMutabilityPlan.instance();
|
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()
|
if ( !domainJtd.getMutabilityPlan().isMutable()
|
||||||
&& !isCollection( domainJtd.getJavaTypeClass() ) ) {
|
&& !isCollection( domainJtd.getJavaTypeClass() ) ) {
|
||||||
return ImmutableMutabilityPlan.instance();
|
return ImmutableMutabilityPlan.instance();
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.mapping.collections.asbasic;
|
package org.hibernate.orm.test.mapping.collections.asbasic;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
|
|
||||||
import jakarta.persistence.AttributeConverter;
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
|
||||||
|
|
||||||
import static org.hibernate.internal.util.StringHelper.join;
|
import static org.hibernate.internal.util.StringHelper.join;
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.listOf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -31,7 +36,7 @@ public class CommaDelimitedStringsConverter implements AttributeConverter<List<S
|
||||||
if ( dbData == null ) {
|
if ( dbData == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Arrays.asList( dbData.split( "," ) );
|
return listOf( dbData.split( "," ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//end::ex-csv-converter[]
|
//end::ex-csv-converter[]
|
||||||
|
|
|
@ -63,6 +63,13 @@ public class CommaDelimitedStringsConverterTests {
|
||||||
final Person loaded = session.byId( Person.class ).load( 1 );
|
final Person loaded = session.byId( Person.class ).load( 1 );
|
||||||
assertThat( loaded.nickNames ).hasSize( 2 );
|
assertThat( loaded.nickNames ).hasSize( 2 );
|
||||||
assertThat( loaded.nickNames ).containsExactly( "John Q. Public", "Joe Public" );
|
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 );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue