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
if ( nullability != Nullability.FORCED_NULL
&& inferredData.getClassOrElement().isPrimitive()
&& !inferredData.getProperty().isArray() ) {
&& !PropertyBinder.isOptional( inferredData.getProperty(), propertyHolder ) ) {
column.setNullable( false );
}
final String propertyName = inferredData.getPropertyName();

View File

@ -452,7 +452,7 @@ public class PropertyBinder {
private void handleOptional(Property property) {
if ( this.property != null ) {
property.setOptional( !isId && isOptional( this.property ) );
property.setOptional( !isId && isOptional( this.property, this.holder ) );
if ( property.isOptional() ) {
final OptionalDeterminationSecondPass secondPass = persistentClasses -> {
// 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
* account whether it is primitive?
*/
private static boolean isOptional(XProperty property) {
public static boolean isOptional(XProperty property, PropertyHolder propertyHolder) {
return property.isAnnotationPresent( Basic.class )
? 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) {

View File

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