{"record":{"id":"eefbb009639683bd","repo":"hibernate/hibernate-orm","slug":"function-argument-s-at-specified-position-d","errorCode":null,"errorMessage":"Function argument [%s] at specified position [%d] in call arguments was not typed as an allowable function return type","messagePattern":"Function argument \\[(.+?)\\] at specified position \\[(.+?)\\] in call arguments was not typed as an allowable function return type","errorType":"exception","errorClass":"FunctionArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java","lineNumber":261,"sourceCode":"//\t\t\t\t\t\t)\n//\t\t\t\t);\n//\t\t\t}\n//\n//\t\t\treturn basicType.getJdbcMapping();\n//\t\t}\n//\t}\n\n\tpublic static BasicValuedMapping extractArgumentValuedMapping(List<? extends SqlAstNode> arguments, int position) {\n\t\tfinal SqlAstNode specifiedArgument = arguments.get( position-1 );\n\t\tfinal var specifiedArgType =\n\t\t\t\tspecifiedArgument instanceof Expression expression\n\t\t\t\t\t\t? expression.getExpressionType()\n\t\t\t\t\t\t: null;\n\t\tif ( specifiedArgType instanceof BasicValuedMapping basicValuedMapping ) {\n\t\t\treturn basicValuedMapping;\n\t\t}\n\t\telse {\n\t\t\tthrow new FunctionArgumentException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Function argument [%s] at specified position [%d] in call arguments was not typed as an allowable function return type\",\n\t\t\t\t\t\t\tspecifiedArgument,\n\t\t\t\t\t\t\tposition\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n}\n","sourceCodeStart":243,"sourceCodeEnd":272,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java#L243-L272","documentation":"extractArgumentValuedMapping(arguments, position) is the SQL-AST-level counterpart used during function rendering: it takes the rendered argument expression at the given 1-based position and requires its expression type to be a BasicValuedMapping (a basic, JDBC-mappable value). If the argument expression resolves to anything else - null, an embedded, entity, or plural mapping - it throws FunctionArgumentException during query interpretation.","triggerScenarios":"A custom function whose rendering path (or set-returning resolver) calls extractArgumentValuedMapping on an argument that is not basic-valued: passing an embeddable or association path (e.g. e.address) into a function that only handles basic columns.","commonSituations":"Functions that worked on simple columns then applied to embedded/association attributes; a version upgrade where an argument that used to be basic became a mapped component; an off-by-one in the position after editing the function signature.","solutions":["Dereference to a basic attribute before calling the function: my_func(e.address.zip) or my_func(e.assoc.id).","Verify the position argument (it is 1-based) actually points at the basic-valued argument.","If optional arguments can reach the helper, filter them out of the list before extraction.","Prefer invariant return types for functions whose arguments are not guaranteed to stay basic."],"exampleFix":"// before - e.address is an embeddable, not basic-valued\nselect my_func(e.address) from Employee e\n\n// after - target a basic attribute inside it\nselect my_func(e.address.zip) from Employee e","handlingStrategy":"validation","validationCode":"static boolean isBasicValued(SqmTypedNode<?> node) {\n    return node.getNodeType() instanceof BasicType;\n}","typeGuard":null,"tryCatchPattern":"try {\n    query.getResultList();\n} catch (org.hibernate.query.sqm.produce.function.FunctionArgumentException e) {\n    // message names the offending argument and its position\n    throw new IllegalArgumentException(e.getMessage(), e);\n}","preventionTips":["Route only basic attributes into functions that extract BasicValuedMappings; dereference embeddables and associations first.","Re-verify argument positions (1-based) whenever a custom function's pattern or signature is edited.","Cover each function with a rendering test against the actual mapped entity model."],"tags":["hibernate","sql-ast","function","basic-type","rendering"],"backgroundTag":"function-return-type-resolution-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}