hibernate/hibernate-orm · error · QueryException

CockroachDB json_value only support literal json paths, but…

Error message

CockroachDB json_value only support literal json paths, but got " + arguments.jsonPath()

What it means

Thrown during SQL rendering when a CockroachDB json_query function is given a JSON path that is not a compile-time literal (e.g. a parameter or dynamically computed path). CockroachDB lacks jsonb_path_query, so Hibernate emulates it with the #> operator, which can only embed a literal path string; a parameterized path cannot be translated, so rendering fails with a QueryException. Fix by using a literal JSON path or passing dynamic path parts as separate arguments.

Solutions

  1. Pass the JSON path as a string literal.
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: CockroachDB json_value only support literal json paths.

Common situations: Common when running against a database whose dialect lacks this capability, when a mapping or HQL/Criteria query requests unsupported functionality, or when the wrong dialect is configured for the database in use. Error: CockroachDB json_value only support literal json paths.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/CockroachDBJsonQueryFunction.java:56

		// jsonb_path_query functions error by default
		if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonQueryErrorBehavior.ERROR ) {
			throw new QueryException( "Can't emulate on error clause on CockroachDB" );
		}
		if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonQueryEmptyBehavior.NULL ) {
			throw new QueryException( "Can't emulate on empty clause on CockroachDB" );
		}
		final JsonQueryWrapMode wrapMode = arguments.wrapMode();

		if ( wrapMode == JsonQueryWrapMode.WITH_WRAPPER ) {
			sqlAppender.appendSql( "jsonb_build_array(" );
		}
		final Expression jsonDocumentExpression = arguments.jsonDocument();
		final String jsonPath;
		try {
			jsonPath = walker.getLiteralValue( arguments.jsonPath() );
		}
		catch (Exception ex) {
			throw new QueryException( "CockroachDB json_value only support literal json paths, but got " + arguments.jsonPath() );
		}
		appendJsonQuery(
				sqlAppender,
				jsonDocumentExpression,
				JsonPathHelper.parseJsonPathElements( jsonPath ),
				arguments.isJsonType(),
				arguments.passingClause(),
				walker
		);

		if ( wrapMode == JsonQueryWrapMode.WITH_WRAPPER ) {
			sqlAppender.appendSql( ")" );
		}
	}

	static void appendJsonQuery(
			SqlAppender sqlAppender,
			Expression jsonDocumentExpression,

View on GitHub (pinned to fad1729dce)