Skip to content

Commit e4619c3

Browse files
committed
HHH-19035 add UserType.isComparable()
To allow a UserType to override the determination made by the JdbcType.
1 parent 54e160a commit e4619c3

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ private int validateArgument(int paramNumber, JdbcMappingContainer expressionTyp
203203
final int jdbcTypeCount = expressionType.getJdbcTypeCount();
204204
for ( int i = 0; i < jdbcTypeCount; i++ ) {
205205
final JdbcMapping mapping = expressionType.getJdbcMapping( i );
206-
FunctionParameterType type = paramNumber < types.length ? types[paramNumber++] : types[types.length - 1];
206+
final FunctionParameterType type =
207+
paramNumber < types.length
208+
? types[paramNumber++]
209+
: types[types.length - 1];
207210
if ( type != null ) {
208211
checkArgumentType(
209212
paramNumber,

hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeSqlTypeAdapter.java renamed to hibernate-core/src/main/java/org/hibernate/type/internal/UserTypeJdbcTypeAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public int getJdbcTypeCode() {
5353
return userType.getSqlType();
5454
}
5555

56+
@Override
57+
public boolean isComparable() {
58+
final Boolean comparable = userType.isComparable();
59+
return comparable == null ? JdbcType.super.isComparable() : comparable;
60+
}
61+
5662
@Override
5763
@SuppressWarnings("unchecked")
5864
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) {

hibernate-core/src/main/java/org/hibernate/usertype/UserType.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,19 @@ default JdbcType getJdbcType(TypeConfiguration typeConfiguration) {
524524
default BasicValueConverter<J, Object> getValueConverter() {
525525
return null;
526526
}
527+
528+
/**
529+
* Is this a comparable type in HQL? A type is comparable if it may be
530+
* used with comparison operators like {@code >=}, and with {@code max()}
531+
* and {@code min()}.
532+
*
533+
* @return {@code null} by default to indicate that the assigned
534+
* {@code JdbcType} should decide
535+
*
536+
* @since 7.0
537+
*/
538+
@Incubating
539+
default Boolean isComparable() {
540+
return null;
541+
}
527542
}

0 commit comments

Comments
 (0)