From 70114d30ece5492e75f995a6a9e28281a177606c Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 16 Dec 2021 18:22:17 +0100 Subject: [PATCH] treat integral types as equivalent for purposes of schema validation/update --- .../src/main/java/org/hibernate/dialect/Dialect.java | 8 ++++++++ .../type/descriptor/java/EnumJavaTypeDescriptor.java | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index f5c4a65527..4bd3b01b90 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -1293,6 +1293,7 @@ public abstract class Dialect implements ConversionContext { public boolean equivalentTypes(int typeCode1, int typeCode2) { return typeCode1==typeCode2 || isNumericOrDecimal(typeCode1) && isNumericOrDecimal(typeCode2) + || isIntegral(typeCode1) && isIntegral(typeCode2) || isFloatOrRealOrDouble(typeCode1) && isFloatOrRealOrDouble(typeCode2) || isVarcharType(typeCode1) && isVarcharType(typeCode2) || isVarbinaryType(typeCode1) && isVarbinaryType(typeCode2); @@ -1309,6 +1310,13 @@ public abstract class Dialect implements ConversionContext { || typeCode == Types.DOUBLE; } + private static boolean isIntegral(int typeCode) { + return typeCode == Types.INTEGER + || typeCode == Types.BIGINT + || typeCode == Types.SMALLINT + || typeCode == Types.TINYINT; + } + /** * Retrieve a set of default Hibernate properties for this database. * diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaTypeDescriptor.java index f622e7f3f8..56d1297184 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaTypeDescriptor.java @@ -13,6 +13,7 @@ import org.hibernate.dialect.Dialect; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; +import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; /** * Describes a Java Enum type. @@ -27,19 +28,20 @@ public class EnumJavaTypeDescriptor> extends AbstractClassJava @Override public JdbcType getRecommendedJdbcType(JdbcTypeDescriptorIndicators context) { + JdbcTypeRegistry registry = context.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); if ( context.getEnumeratedType() != null && context.getEnumeratedType() == EnumType.STRING ) { if ( context.getColumnLength() == 1 ) { return context.isNationalized() - ? context.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.NCHAR ) - : context.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.CHAR ); + ? registry.getDescriptor( Types.NCHAR ) + : registry.getDescriptor( Types.CHAR ); } return context.isNationalized() - ? context.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.NVARCHAR ) - : context.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.VARCHAR ); + ? registry.getDescriptor( Types.NVARCHAR ) + : registry.getDescriptor( Types.VARCHAR ); } else { - return context.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.TINYINT ); + return registry.getDescriptor( Types.TINYINT ); } }