From 09de87d2794c5d1a02c9e71cc5c23da6c72a1d4c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 11 Dec 2025 11:25:27 -0700 Subject: [PATCH] HHH-3192 - SchemaValidator column nullability check --- .../internal/AbstractSchemaValidator.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java index 2df34e1b52f9..25a404c62ba1 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java @@ -139,6 +139,7 @@ protected void validateTable( ); } validateColumnType( table, column, existingColumn, metadata, dialect ); + validateColumnNullability( table, column, existingColumn ); } } @@ -164,6 +165,22 @@ protected void validateColumnType( } } + private void validateColumnNullability(Table table, Column column, ColumnInformation existingColumn) { + if ( existingColumn.getNullable() == Boolean.FALSE ) { + // the existing schema column is defined as not-nullable + if ( column.isNullable() ) { + // but it is mapped in the model as nullable + throw new SchemaManagementException( + String.format( + "Schema validation: column defined as not-null in the database, but nullable in model - [%s] in table [%s]", + column.getName(), + table.getQualifiedTableName() + ) + ); + } + } + } + protected void validateSequence(Sequence sequence, SequenceInformation sequenceInformation) { if ( sequenceInformation == null ) { throw new SchemaManagementException(