From 532b63042c8ce68e99ebe9c3244a3675d7767860 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Fri, 11 Mar 2016 01:30:53 -0800 Subject: [PATCH] HHH-10360 : Natural ID columns are nullable by default (cherry picked from commit 10a035481d9f13c707b606d97d9f0cc5a8bccc8e) --- .../boot/model/source/internal/hbm/ModelBinder.java | 2 +- .../internal/hbm/SingularAttributeSourceBasicImpl.java | 5 ++++- .../internal/hbm/SingularAttributeSourceManyToOneImpl.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index ad518d87a8..79024e2eb1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -1889,7 +1889,7 @@ public class ModelBinder { sourceDocument, attributeSource.getRelationalValueSources(), value, - true, + attributeSource.areValuesNullableByDefault(), new RelationalObjectBinder.ColumnNamingDelegate() { @Override public Identifier determineImplicitName(LocalMetadataBuildingContext context) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceBasicImpl.java index 14ef4d529d..8a8f10437f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceBasicImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceBasicImpl.java @@ -171,7 +171,10 @@ class SingularAttributeSourceBasicImpl @Override public boolean areValuesNullableByDefault() { - return ! Helper.getValue( propertyElement.isNotNull(), false ); + return ! Helper.getValue( + propertyElement.isNotNull(), + naturalIdMutability != NaturalIdMutability.NOT_NATURAL_ID + ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceManyToOneImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceManyToOneImpl.java index a28fdfaf56..18509bd002 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceManyToOneImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceManyToOneImpl.java @@ -216,7 +216,7 @@ class SingularAttributeSourceManyToOneImpl @Override public boolean areValuesNullableByDefault() { - return true; + return getNaturalIdMutability() == NaturalIdMutability.NOT_NATURAL_ID; } @Override