Skip to content

Commit 48c85c2

Browse files
committed
HHH-3192 - SchemaValidator column nullability check
1 parent f144b9f commit 48c85c2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 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 );
142143
}
143144
}
144145

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

168+
private void validateColumnNullability(Table table, Column column, ColumnInformation existingColumn) {
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] in table [%s]",
176+
column.getName(),
177+
table.getQualifiedTableName()
178+
)
179+
);
180+
}
181+
}
182+
}
183+
167184
protected void validateSequence(Sequence sequence, SequenceInformation sequenceInformation) {
168185
if ( sequenceInformation == null ) {
169186
throw new SchemaManagementException(

0 commit comments

Comments
 (0)