Skip to content

Commit d038b23

Browse files
committed
HHH-3192 - SchemaValidator nullability check
1 parent f144b9f commit d038b23

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ protected void validateTable(
139139
);
140140
}
141141
validateColumnType( table, column, existingColumn, metadata, dialect );
142+
validateColumnNullability( table, column, existingColumn, metadata, dialect );
142143
}
143144
}
144145

@@ -164,6 +165,21 @@ protected void validateColumnType(
164165
}
165166
}
166167

168+
private void validateColumnNullability(Table table, Column column, ColumnInformation existingColumn, Metadata metadata, Dialect dialect) {
169+
if ( existingColumn.getNullable() == Boolean.FALSE ) {
170+
// the existing schema column is defined as not-nullable
171+
if ( column.isNullable() ) {
172+
// but it is mapped in the model as nullable
173+
throw new SchemaManagementException(
174+
String.format(
175+
"Schema validation: column defined as not-null in the database, but nullable in model [%s]",
176+
column.getName()
177+
)
178+
);
179+
}
180+
}
181+
}
182+
167183
protected void validateSequence(Sequence sequence, SequenceInformation sequenceInformation) {
168184
if ( sequenceInformation == null ) {
169185
throw new SchemaManagementException(

0 commit comments

Comments
 (0)