HHH-17290 Embeddable with a primitive field cannot be set to null

This commit is contained in:
Andrea Boriero 2023-10-05 17:36:28 +02:00 committed by Christian Beikov
parent 04f18cc6a2
commit 178f68547b
3 changed files with 8 additions and 8 deletions

View File

@ -900,8 +900,7 @@ public class AnnotatedColumn {
// } // }
//not following the spec but more clean //not following the spec but more clean
if ( nullability != Nullability.FORCED_NULL if ( nullability != Nullability.FORCED_NULL
&& inferredData.getClassOrElement().isPrimitive() && !PropertyBinder.isOptional( inferredData.getProperty(), propertyHolder ) ) {
&& !inferredData.getProperty().isArray() ) {
column.setNullable( false ); column.setNullable( false );
} }
final String propertyName = inferredData.getPropertyName(); final String propertyName = inferredData.getPropertyName();

View File

@ -452,7 +452,7 @@ public class PropertyBinder {
private void handleOptional(Property property) { private void handleOptional(Property property) {
if ( this.property != null ) { if ( this.property != null ) {
property.setOptional( !isId && isOptional( this.property ) ); property.setOptional( !isId && isOptional( this.property, this.holder ) );
if ( property.isOptional() ) { if ( property.isOptional() ) {
final OptionalDeterminationSecondPass secondPass = persistentClasses -> { final OptionalDeterminationSecondPass secondPass = persistentClasses -> {
// Defer determining whether a property and its columns are nullable, // Defer determining whether a property and its columns are nullable,
@ -1201,10 +1201,12 @@ public class PropertyBinder {
* Should this property be considered optional, taking into * Should this property be considered optional, taking into
* account whether it is primitive? * account whether it is primitive?
*/ */
private static boolean isOptional(XProperty property) { public static boolean isOptional(XProperty property, PropertyHolder propertyHolder) {
return property.isAnnotationPresent( Basic.class ) return property.isAnnotationPresent( Basic.class )
? property.getAnnotation( Basic.class ).optional() ? property.getAnnotation( Basic.class ).optional()
: property.isArray() || !property.getClassOrElementClass().isPrimitive(); : property.isArray()
|| propertyHolder != null && propertyHolder.isComponent()
|| !property.getClassOrElementClass().isPrimitive();
} }
private static boolean isLazy(XProperty property) { private static boolean isLazy(XProperty property) {

View File

@ -500,7 +500,7 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen
Object owner, Object owner,
Map<Object, Object> copyCache) { Map<Object, Object> copyCache) {
if ( original == null && target == null ) { if ( original == null ) {
return null; return null;
} }
@ -533,10 +533,9 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen
Map<Object, Object> copyCache, Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection) { ForeignKeyDirection foreignKeyDirection) {
if ( original == null && target == null ) { if ( original == null ) {
return null; return null;
} }
final Object[] originalValues = getPropertyValues( original ); final Object[] originalValues = getPropertyValues( original );
final Object[] resultValues = getPropertyValues( target ); final Object[] resultValues = getPropertyValues( target );
final Object[] replacedValues = TypeHelper.replace( final Object[] replacedValues = TypeHelper.replace(