HHH-15823 Fallback to value type ignoring typeInferenceSource

This commit is contained in:
Marco Belladelli 2022-12-14 13:49:17 +01:00 committed by Christian Beikov
parent ba1feef1f8
commit 3d72eabf6c
1 changed files with 28 additions and 10 deletions

View File

@ -1133,12 +1133,19 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
return new SqmLiteral<>( value, expressible, this ); return new SqmLiteral<>( value, expressible, this );
} }
// Just like in HQL, we allow coercion of literal values to the inferred type // Just like in HQL, we allow coercion of literal values to the inferred type
T coercedValue = expressible.getExpressibleJavaType().coerce( value, this::getTypeConfiguration );
if (expressible.getExpressibleJavaType().isInstance( coercedValue )) {
return new SqmLiteral<>( return new SqmLiteral<>(
expressible.getExpressibleJavaType().coerce( value, this::getTypeConfiguration ), coercedValue,
expressible, expressible,
this this
); );
} }
else {
// ignore typeInferenceSource and fallback the value type
return literal( value );
}
}
private static <T> SqmExpressible<T> resolveInferredType( private static <T> SqmExpressible<T> resolveInferredType(
T value, T value,
@ -1700,12 +1707,23 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
); );
} }
final SqmExpressible<T> expressible = bindableType.resolveExpressible( getTypeConfiguration().getSessionFactory() ); final SqmExpressible<T> expressible = bindableType.resolveExpressible( getTypeConfiguration().getSessionFactory() );
T coercedValue = expressible.getExpressibleJavaType().coerce( value, this::getTypeConfiguration );
if ( isInstance( bindableType, coercedValue ) ) {
return new ValueBindJpaCriteriaParameter<>( return new ValueBindJpaCriteriaParameter<>(
bindableType, bindableType,
expressible.getExpressibleJavaType().coerce( value, this::getTypeConfiguration ), coercedValue,
this this
); );
} }
else {
// ignore typeInferenceSource and fallback the value type
return new ValueBindJpaCriteriaParameter<>(
queryEngine.getTypeConfiguration().getSessionFactory().resolveParameterBindType( value ),
value,
this
);
}
}
private <T> boolean isInstance(BindableType<T> bindableType, T value) { private <T> boolean isInstance(BindableType<T> bindableType, T value) {
if ( bindableType instanceof SqmExpressible<?> ) { if ( bindableType instanceof SqmExpressible<?> ) {