hibernate/hibernate-orm · error · QueryException

JSON path [" + jsonPath + "] uses parameter [" + parameterNa

Error message

JSON path [" + jsonPath + "] uses parameter [" + parameterName + "] that is not passed

What it means

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.

Source

Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonQueryFunction.java:64

			catch (Exception ex) {
				throw new QueryException( "SingleStore json_query only support literal json paths, but got " + arguments.jsonPath() );
			}
			final List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements( jsonPath );
			final JsonQueryWrapMode wrapMode = arguments.wrapMode();
			final DecorationMode decorationMode = determineDecorationMode( wrapMode );
			if ( decorationMode == DecorationMode.WRAP ) {
				sqlAppender.appendSql( "concat('['," );
			}
			sqlAppender.appendSql( "nullif(json_extract_string(" );
			arguments.jsonDocument().accept( walker );
			for ( JsonPathHelper.JsonPathElement pathElement : jsonPathElements ) {
				sqlAppender.appendSql( ',' );
				if ( pathElement instanceof JsonPathHelper.JsonAttribute attribute ) {
					sqlAppender.appendSingleQuoteEscapedString( attribute.attribute() );
				}
				else if ( pathElement instanceof JsonPathHelper.JsonParameterIndexAccess indexParameter) {
					final String parameterName = indexParameter.parameterName();
					throw new QueryException( "JSON path [" + jsonPath + "] uses parameter [" + parameterName + "] that is not passed" );
				}
				else {
					sqlAppender.appendSql( '\'' );
					sqlAppender.appendSql( ( (JsonPathHelper.JsonIndexAccess) pathElement ).index() );
					sqlAppender.appendSql( '\'' );
				}
			}
			sqlAppender.appendSql( "),'null')" );
			if ( decorationMode == DecorationMode.WRAP ) {
				sqlAppender.appendSql( ",']')" );
			}
		}
	}

	enum DecorationMode {NONE, WRAP}

	private static DecorationMode determineDecorationMode(JsonQueryWrapMode wrapMode) {
		if ( wrapMode == JsonQueryWrapMode.WITH_WRAPPER ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove the $param reference and the 'passing' clause; use a literal index: '$.arr[3]'.
  2. Build the path string dynamically with the index interpolated as a literal (validate it is an integer first).
  3. Fetch the array with json_query and pick the element in Java.
  4. Use a native query against SingleStore's json_extract functions where the index can be bound.

Example fix

// before - throws: $i is a path parameter
select json_query(e.doc, '$.items[$i]' passing e.idx as i) from Event e

// after - literal index
select json_query(e.doc, '$.items[0]') from Event e
Defensive patterns

Strategy: fallback

Validate before calling

// Ensure the generated path contains no $param references before executing
if (path.matches(".*\$[A-Za-z_].*")) throw new IllegalArgumentException("path parameters unsupported: " + path);
// build literal path instead: "$.arr[" + validatedIndex + "]"

Try / catch

try {
    return session.createQuery(hql, String.class).getSingleResult();
} catch (QueryException e) {
    if (e.getMessage().contains("that is not passed")) {
        return fetchArrayAndIndexInJava(session); // fallback
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Parametrized array indexing written for Oracle/PostgreSQL JSON syntax; reusable queries that index JSON arrays by a runtime value; migrating such queries to SingleStore.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/8a2f19cdeb62e438. Report an issue: GitHub.