From 0d9ef5444afbb6da2185811564980824139ea402 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 12 Apr 2023 10:38:42 +0200 Subject: [PATCH] HHH-16425 Handle path sources in function return type resolvers --- .../StandardFunctionReturnTypeResolvers.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java index bbb33e19df..62bd9d9430 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java @@ -18,6 +18,7 @@ import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.query.ReturnableType; import org.hibernate.query.sqm.SqmExpressible; +import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.Expression; @@ -103,10 +104,14 @@ public class StandardFunctionReturnTypeResolvers { } @Override - public ReturnableType resolveFunctionReturnType(ReturnableType impliedType, List> arguments, TypeConfiguration typeConfiguration) { - for (SqmTypedNode arg: arguments) { - if (arg!=null && arg.getNodeType() instanceof ReturnableType ) { - ReturnableType argType = (ReturnableType) arg.getNodeType(); + public ReturnableType resolveFunctionReturnType( + ReturnableType impliedType, + List> arguments, + TypeConfiguration typeConfiguration) { + for ( SqmTypedNode arg : arguments ) { + final SqmExpressible argumentNodeType = arg != null ? getArgumentExpressible( arg ) : null; + if ( argumentNodeType instanceof ReturnableType ) { + ReturnableType argType = (ReturnableType) argumentNodeType; return isAssignableTo( argType, impliedType ) ? impliedType : argType; } } @@ -208,7 +213,7 @@ public class StandardFunctionReturnTypeResolvers { List> arguments, int position) { final SqmTypedNode specifiedArgument = arguments.get( position - 1 ); - final SqmExpressible specifiedArgType = specifiedArgument.getNodeType(); + final SqmExpressible specifiedArgType = getArgumentExpressible( specifiedArgument ); if ( !(specifiedArgType instanceof ReturnableType ) ) { throw new QueryException( String.format( @@ -224,6 +229,13 @@ public class StandardFunctionReturnTypeResolvers { return (ReturnableType) specifiedArgType; } + private static SqmExpressible getArgumentExpressible(SqmTypedNode specifiedArgument) { + final SqmExpressible specifiedArgType = specifiedArgument.getNodeType(); + return specifiedArgType instanceof SqmPathSource ? + ( (SqmPathSource) specifiedArgType ).getSqmPathType() : + specifiedArgType; + } + public static JdbcMapping extractArgumentJdbcMapping( TypeConfiguration typeConfiguration, List> arguments,