Skip to content

Commit 5d2bedc

Browse files
committed
HHH-19276 use TypecheckUtil to test assignability of array elements
1 parent ba55552 commit 5d2bedc

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/function/array/ArrayAndElementArgumentValidator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;
1212
import org.hibernate.query.sqm.tree.SqmTypedNode;
1313

14+
import static org.hibernate.query.sqm.internal.TypecheckUtil.isTypeAssignable;
15+
1416
/**
1517
* A {@link ArgumentsValidator} that validates the array type is compatible with the element type.
1618
*/
@@ -37,8 +39,9 @@ public void validate(
3739
final var expressible = elementArgument.getExpressible();
3840
final var elementType = expressible != null ? expressible.getSqmType() : null;
3941
if ( expectedElementType != null && elementType != null
40-
&& !expectedElementType.getJavaType()
41-
.isAssignableFrom( elementType.getExpressibleJavaType().getJavaTypeClass() ) ) {
42+
&& !isTypeAssignable( expectedElementType, elementType.getSqmType(), bindingContext ) ) {
43+
// && !expectedElementType.getRelationalJavaType().getJavaTypeClass()
44+
// .isAssignableFrom( elementType.getRelationalJavaType().getJavaTypeClass() ) ) {
4245
throw new FunctionArgumentException(
4346
String.format(
4447
"Parameter %d of function '%s()' has type %s, but argument is of type '%s'",

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/TypecheckUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ else if ( rhsType instanceof SqmBindableType<?> rhsExpressible ) {
312312
*
313313
* @see #areTypesComparable(SqmBindableType, SqmBindableType, BindingContext)
314314
*/
315-
private static boolean isTypeAssignable(
315+
public static boolean isTypeAssignable(
316316
SqmBindableType<?> targetType, SqmBindableType<?> expressionType,
317317
BindingContext bindingContext) {
318318

0 commit comments

Comments
 (0)