From 86c2a0062dd7daf91b9729157538819a94445952 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 26 Sep 2023 10:00:01 +0200 Subject: [PATCH] HHH-17233 be a little more forgiving when comparing column types in schema validation this "fix" is not really strictly-speaking necessary, but it does reduce false positives in a very tiny number of cases --- .../schema/internal/ColumnDefinitions.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java index 8dada330fd..d19450f336 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java @@ -20,6 +20,7 @@ import org.hibernate.tool.schema.extract.spi.ColumnInformation; import org.hibernate.type.descriptor.jdbc.JdbcType; import java.util.List; +import java.util.Locale; import static org.hibernate.type.SqlTypes.isNumericOrDecimal; import static org.hibernate.type.SqlTypes.isStringType; @@ -28,7 +29,7 @@ class ColumnDefinitions { static boolean hasMatchingType(Column column, ColumnInformation columnInformation, Metadata metadata, Dialect dialect) { boolean typesMatch = dialect.equivalentTypes( column.getSqlTypeCode(metadata), columnInformation.getTypeCode() ) - || stripArgs( getSqlType( column, metadata ) ).equalsIgnoreCase( columnInformation.getTypeName() ); + || normalize( stripArgs( getSqlType( column, metadata ) ) ).equals( normalize( columnInformation.getTypeName() ) ); if ( typesMatch ) { return true; } @@ -239,8 +240,32 @@ class ColumnDefinitions { ); } - private static String stripArgs(String string) { - int i = string.indexOf( '(' ); - return i > 0 ? string.substring( 0, i ).trim() : string; + private static String normalize(String typeName) { + if ( typeName == null ) { + return null; + } + else { + final String lowerCaseTypName = typeName.toLowerCase(Locale.ROOT); + switch (lowerCaseTypName) { + case "character": + return "char"; + case "character varying": + return "varchar"; + case "binary varying": + return "varbinary"; + default: + return lowerCaseTypName; + } + } + } + + private static String stripArgs(String typeExpression) { + if ( typeExpression == null ) { + return null; + } + else { + int i = typeExpression.indexOf( '(' ); + return i > 0 ? typeExpression.substring( 0, i ).trim() : typeExpression; + } } }