{"record":{"id":"04ea9b0dcb58eecb","repo":"hibernate/hibernate-orm","slug":"json-path-jsonpathhelper-tojsonpath-jsonpath-04ea9b","errorCode":null,"errorMessage":"JSON path [\" + JsonPathHelper.toJsonPath( jsonPathElements ) + \"] uses parameter [\" + parameterName + \"] that is not passed","messagePattern":"JSON path \\[\" \\+ JsonPathHelper\\.toJsonPath\\( jsonPathElements \\) \\+ \"\\] uses parameter \\[\" \\+ parameterName \\+ \"\\] that is not passed","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/json/CockroachDBJsonValueFunction.java","lineNumber":102,"sourceCode":"\t\t\tsqlAppender.appendSql( \" as jsonb)\" );\n\t\t}\n\t\telse {\n\t\t\tsqlAppender.appendSql( ')' );\n\t\t}\n\t\tsqlAppender.appendSql( \"#>>array\" );\n\t\tchar separator = '[';\n\t\tfinal Dialect dialect = walker.getSessionFactory().getJdbcServices().getDialect();\n\t\tfor ( JsonPathHelper.JsonPathElement jsonPathElement : jsonPathElements ) {\n\t\t\tsqlAppender.appendSql( separator );\n\t\t\tif ( jsonPathElement instanceof JsonPathHelper.JsonAttribute attribute ) {\n\t\t\t\tdialect.appendLiteral( sqlAppender, attribute.attribute() );\n\t\t\t}\n\t\t\telse if ( jsonPathElement instanceof JsonPathHelper.JsonParameterIndexAccess ) {\n\t\t\t\tassert jsonPathPassingClause != null;\n\t\t\t\tfinal String parameterName = ( (JsonPathHelper.JsonParameterIndexAccess) jsonPathElement ).parameterName();\n\t\t\t\tfinal Expression expression = jsonPathPassingClause.getPassingExpressions().get( parameterName );\n\t\t\t\tif ( expression == null ) {\n\t\t\t\t\tthrow new QueryException( \"JSON path [\" + JsonPathHelper.toJsonPath( jsonPathElements ) + \"] uses parameter [\" + parameterName + \"] that is not passed\" );\n\t\t\t\t}\n\n\t\t\t\tsqlAppender.appendSql( \"cast(\" );\n\t\t\t\texpression.accept( walker );\n\t\t\t\tsqlAppender.appendSql( \" as text)\" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsqlAppender.appendSql( '\\'' );\n\t\t\t\tsqlAppender.appendSql( ( (JsonPathHelper.JsonIndexAccess) jsonPathElement ).index() );\n\t\t\t\tsqlAppender.appendSql( '\\'' );\n\t\t\t}\n\t\t\tseparator = ',';\n\t\t}\n\t\tif ( jsonPathElements.isEmpty() ) {\n\t\t\tsqlAppender.appendSql( '[' );\n\t\t}\n\t\tsqlAppender.appendSql( ']' );\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/json/CockroachDBJsonValueFunction.java#L84-L120","documentation":"When the CockroachDB json_value() emulation rewrites a literal JSON path, $name tokens inside the path (parameter index access such as $.items[$i]) are resolved against the query's PASSING clause bindings. If a name referenced by the path has no matching passing expression - jsonPathPassingClause.getPassingExpressions().get(name) returns null - rendering aborts with this QueryException.","triggerScenarios":"A literal path that references a parameter which is never bound, or is bound under a different name: select json_value(d.doc, '$.tags[$i]') from Document d with no passing clause, or json_value(d.doc, '$.tags[$i]' passing :idx as index) where the path uses 'i' but the alias defined is 'index'.","commonSituations":"Renaming a bind alias without updating the path string; case mismatches between the path token and the AS alias (matching is case-sensitive); copy-pasting a path from documentation that references parameters the query never defines.","solutions":["Add the missing binding: json_value(d.doc, '$.tags[$i]' passing :idx as i)","Make the names match exactly - the token inside $[...] must equal the AS alias in the PASSING clause, case-sensitively","Remove the parameter token from the path if it was accidental and use a literal index","Add a unit test that extracts $tokens from your paths and asserts each has a PASSING alias"],"exampleFix":"// before - path uses $i but nothing is passed for it\nselect json_value(d.doc, '$.tags[$i]') from Document d\n\n// after - bind i through the passing clause\nselect json_value(d.doc, '$.tags[$i]' passing :idx as i) from Document d","handlingStrategy":"validation","validationCode":"// Every $name token inside a literal path must have a matching PASSING alias\nstatic void assertPassingBindings(String literalPath, java.util.Set<String> passingAliases) {\n    java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"\\\\$([A-Za-z_]\\\\w*)\").matcher(literalPath);\n    while (m.find()) {\n        if (!passingAliases.contains(m.group(1))) {\n            throw new IllegalArgumentException(\n                \"JSON path parameter '\" + m.group(1) + \"' is not bound by a PASSING clause\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(hql, String.class).getResultList();\n} catch (org.hibernate.QueryException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"that is not passed\")) {\n        throw new IllegalArgumentException(\n            \"Path references a parameter missing from the PASSING clause; check aliases (case-sensitive)\", e);\n    }\n    throw e;\n}","preventionTips":["Define path parameter tokens and PASSING aliases together in one constant/enum pair so they cannot drift","Remember alias matching is case-sensitive: '$.tags[$i]' requires 'passing :idx as i', not 'as I'","Unit-test path strings against the passing map before executing the query"],"tags":["hibernate","cockroachdb","json","hql","json-path","passing-clause","bind-parameter"],"backgroundTag":"json-path-parameter-not-passed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}