{"record":{"id":"8a2f19cdeb62e438","repo":"hibernate/hibernate-orm","slug":"json-path-jsonpath-uses-parameter-p","errorCode":null,"errorMessage":"JSON path [\" + jsonPath + \"] uses parameter [\" + parameterName + \"] that is not passed","messagePattern":"JSON path \\[\" \\+ jsonPath \\+ \"\\] uses parameter \\[\" \\+ parameterName \\+ \"\\] that is not passed","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonQueryFunction.java","lineNumber":64,"sourceCode":"\t\t\tcatch (Exception ex) {\n\t\t\t\tthrow new QueryException( \"SingleStore json_query only support literal json paths, but got \" + arguments.jsonPath() );\n\t\t\t}\n\t\t\tfinal List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements( jsonPath );\n\t\t\tfinal JsonQueryWrapMode wrapMode = arguments.wrapMode();\n\t\t\tfinal DecorationMode decorationMode = determineDecorationMode( wrapMode );\n\t\t\tif ( decorationMode == DecorationMode.WRAP ) {\n\t\t\t\tsqlAppender.appendSql( \"concat('[',\" );\n\t\t\t}\n\t\t\tsqlAppender.appendSql( \"nullif(json_extract_string(\" );\n\t\t\targuments.jsonDocument().accept( walker );\n\t\t\tfor ( JsonPathHelper.JsonPathElement pathElement : jsonPathElements ) {\n\t\t\t\tsqlAppender.appendSql( ',' );\n\t\t\t\tif ( pathElement instanceof JsonPathHelper.JsonAttribute attribute ) {\n\t\t\t\t\tsqlAppender.appendSingleQuoteEscapedString( attribute.attribute() );\n\t\t\t\t}\n\t\t\t\telse if ( pathElement instanceof JsonPathHelper.JsonParameterIndexAccess indexParameter) {\n\t\t\t\t\tfinal String parameterName = indexParameter.parameterName();\n\t\t\t\t\tthrow new QueryException( \"JSON path [\" + jsonPath + \"] uses parameter [\" + parameterName + \"] that is not passed\" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tsqlAppender.appendSql( '\\'' );\n\t\t\t\t\tsqlAppender.appendSql( ( (JsonPathHelper.JsonIndexAccess) pathElement ).index() );\n\t\t\t\t\tsqlAppender.appendSql( '\\'' );\n\t\t\t\t}\n\t\t\t}\n\t\t\tsqlAppender.appendSql( \"),'null')\" );\n\t\t\tif ( decorationMode == DecorationMode.WRAP ) {\n\t\t\t\tsqlAppender.appendSql( \",']')\" );\n\t\t\t}\n\t\t}\n\t}\n\n\tenum DecorationMode {NONE, WRAP}\n\n\tprivate static DecorationMode determineDecorationMode(JsonQueryWrapMode wrapMode) {\n\t\tif ( wrapMode == JsonQueryWrapMode.WITH_WRAPPER ) {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonQueryFunction.java#L46-L82","documentation":"The literal JSON path passed to json_query() contains a '$name' variable reference - produced by HQL's PASSING clause, e.g. '$.items[$idx]' passing someInt as idx. The SingleStore emulation expands the path into literal json_extract_string arguments; when it meets a JsonParameterIndexAccess element it cannot inject the passed parameter into the generated SQL, so it throws this QueryException naming the offending parameter.","triggerScenarios":"HQL like: select json_query(e.doc, '$.arr[$i]' passing e.someIndex as i) from Event e. Any $param reference inside the jsonpath string (index access via a passed variable) hits the JsonParameterIndexAccess branch and throws.","commonSituations":"Parametrized array indexing written for Oracle/PostgreSQL JSON syntax; reusable queries that index JSON arrays by a runtime value; migrating such queries to SingleStore.","solutions":["Remove the $param reference and the 'passing' clause; use a literal index: '$.arr[3]'.","Build the path string dynamically with the index interpolated as a literal (validate it is an integer first).","Fetch the array with json_query and pick the element in Java.","Use a native query against SingleStore's json_extract functions where the index can be bound."],"exampleFix":"// before - throws: $i is a path parameter\nselect json_query(e.doc, '$.items[$i]' passing e.idx as i) from Event e\n\n// after - literal index\nselect json_query(e.doc, '$.items[0]') from Event e","handlingStrategy":"fallback","validationCode":"// Ensure the generated path contains no $param references before executing\nif (path.matches(\".*\\$[A-Za-z_].*\")) throw new IllegalArgumentException(\"path parameters unsupported: \" + path);\n// build literal path instead: \"$.arr[\" + validatedIndex + \"]\"","typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(hql, String.class).getSingleResult();\n} catch (QueryException e) {\n    if (e.getMessage().contains(\"that is not passed\")) {\n        return fetchArrayAndIndexInJava(session); // fallback\n    }\n    throw e;\n}","preventionTips":["Avoid HQL PASSING clauses in queries targeted at SingleStore","Interpolate validated integer indices as literal path segments","Prefer fetching the JSON array and indexing in Java for dynamic access"],"tags":["singlestore","json","json-query","json-path","hql","passing-clause"],"backgroundTag":"unsupported-bind-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}