@@ -1591,6 +1591,10 @@ public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType,
15911591 * {@link Types#VARBINARY BINARY} and
15921592 * {@link Types#LONGVARBINARY LONGVARBINARY} as the same type, since
15931593 * Hibernate doesn't really differentiate these types.
1594+ * <p>
1595+ * On the other hand, integral types are not treated as equivalent,
1596+ * instead, {@link #isCompatibleIntegralType(int, int)} is responsible
1597+ * for determining if the types are compatible.
15941598 *
15951599 * @param typeCode1 the first column type info
15961600 * @param typeCode2 the second column type info
@@ -1600,16 +1604,39 @@ public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType,
16001604 public boolean equivalentTypes (int typeCode1 , int typeCode2 ) {
16011605 return typeCode1 ==typeCode2
16021606 || isNumericOrDecimal (typeCode1 ) && isNumericOrDecimal (typeCode2 )
1603- // || isIntegral(typeCode1) && isIntegral(typeCode2)
16041607 || isFloatOrRealOrDouble (typeCode1 ) && isFloatOrRealOrDouble (typeCode2 )
16051608 || isVarcharType (typeCode1 ) && isVarcharType (typeCode2 )
16061609 || isVarbinaryType (typeCode1 ) && isVarbinaryType (typeCode2 )
1610+ || isCompatibleIntegralType (typeCode1 , typeCode2 )
16071611 // HHH-17908: Since the runtime can cope with enum on the DDL side,
16081612 // but varchar on the ORM expectation side, let's treat the types as equivalent
1609- || isEnumType ( typeCode1 ) && isVarcharType ( typeCode2 )
1613+ || isEnumType (typeCode1 ) && isVarcharType (typeCode2 )
16101614 || sameColumnType (typeCode1 , typeCode2 );
16111615 }
16121616
1617+ /**
1618+ * Tolerate storing {@code short} in {@code INTEGER} or {@code BIGINT}
1619+ * or {@code int} in {@code BIGINT} for the purposes of schema validation
1620+ * and migration.
1621+ */
1622+ private boolean isCompatibleIntegralType (int typeCode1 , int typeCode2 ) {
1623+ switch (typeCode1 ) {
1624+ case TINYINT :
1625+ return typeCode2 == TINYINT
1626+ || typeCode2 == SMALLINT
1627+ || typeCode2 == INTEGER
1628+ || typeCode2 == BIGINT ;
1629+ case SMALLINT :
1630+ return typeCode2 == SMALLINT
1631+ || typeCode2 == INTEGER
1632+ || typeCode2 == BIGINT ;
1633+ case INTEGER :
1634+ return typeCode2 == INTEGER
1635+ || typeCode2 == BIGINT ;
1636+ }
1637+ return false ;
1638+ }
1639+
16131640 private boolean sameColumnType (int typeCode1 , int typeCode2 ) {
16141641 try {
16151642 return Objects .equals ( columnType (typeCode1 ), columnType (typeCode2 ) );
0 commit comments