HHH-15495 Consider UUID to be comparable

This commit is contained in:
Christian Beikov 2022-09-13 20:25:15 +02:00 committed by Andrea Boriero
parent 8b9b02b8b8
commit b392f663c3
2 changed files with 15 additions and 6 deletions

View File

@ -26,7 +26,9 @@ import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
import java.lang.reflect.Type;
import java.sql.Types;
import java.util.List;
import java.util.UUID;
import static org.hibernate.type.SqlTypes.*;
@ -71,7 +73,7 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
JdbcType jdbcType = javaType.getRecommendedJdbcType(indicators);
checkType(
count, functionName, type,
jdbcType.getJdbcTypeCode(),
jdbcType.getDefaultSqlTypeCode(),
javaType.getJavaTypeClass()
);
}
@ -143,7 +145,7 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
if (type != null) {
checkType(
count, functionName, type,
mapping.getJdbcType().getJdbcTypeCode(),
mapping.getJdbcType().getDefaultSqlTypeCode(),
mapping.getJavaTypeDescriptor().getJavaType()
);
}
@ -154,7 +156,11 @@ public class ArgumentTypesValidator implements ArgumentsValidator {
private void checkType(int count, String functionName, FunctionParameterType type, int code, Type javaType) {
switch (type) {
case COMPARABLE:
if ( !isCharacterType(code) && !isTemporalType(code) &&!isNumericType(code) ) {
if ( !isCharacterType(code) && !isTemporalType(code) &&!isNumericType(code) && code != UUID ) {
if ( javaType == java.util.UUID.class && ( code == Types.BINARY || isCharacterType( code ) ) ) {
// We also consider UUID to be comparable when it's a character or binary type
return;
}
throwError(type, javaType, functionName, count);
}
break;

View File

@ -594,7 +594,8 @@ public class SqlTypes {
return typeCode == DATE
|| typeCode == TIME
|| typeCode == TIMESTAMP
|| typeCode == TIMESTAMP_WITH_TIMEZONE;
|| typeCode == TIMESTAMP_WITH_TIMEZONE
|| typeCode == TIMESTAMP_UTC;
}
/**
@ -604,7 +605,8 @@ public class SqlTypes {
public static boolean hasDatePart(int typeCode) {
return typeCode == DATE
|| typeCode == TIMESTAMP
|| typeCode == TIMESTAMP_WITH_TIMEZONE;
|| typeCode == TIMESTAMP_WITH_TIMEZONE
|| typeCode == TIMESTAMP_UTC;
}
/**
@ -614,6 +616,7 @@ public class SqlTypes {
public static boolean hasTimePart(int typeCode) {
return typeCode == TIME
|| typeCode == TIMESTAMP
|| typeCode == TIMESTAMP_WITH_TIMEZONE;
|| typeCode == TIMESTAMP_WITH_TIMEZONE
|| typeCode == TIMESTAMP_UTC;
}
}