hibernate/hibernate-orm · error · QueryException
SingleStore json_value only support literal json paths, but
Error message
SingleStore json_value only support literal json paths, but got " + arguments.jsonPath() + "
What it means
The SingleStore emulation of json_value must parse the JSON path at SQL-render time to expand it into json_extract_string(doc, 'attr', ...) arguments, so the path has to be a literal. When the second argument is a bind parameter, walker.getLiteralValue(arguments.jsonPath()) throws and the dialect rethrows this QueryException stating that only literal paths are supported.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonValueFunction.java:54
throw new QueryException( "Can't emulate on error clause on SingleStore" );
}
if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {
throw new QueryException( "Can't emulate on empty clause on SingleStore" );
}
if ( arguments.returningType() != null ) {
if ( arguments.returningType().getJdbcMapping().getJdbcType().isBoolean() ) {
sqlAppender.append( "case " );
}
else {
sqlAppender.append( "cast(" );
}
}
final String jsonPath;
try {
jsonPath = walker.getLiteralValue( arguments.jsonPath() );
}
catch (Exception ex) {
throw new QueryException( "SingleStore json_value only support literal json paths, but got " + arguments.jsonPath() );
}
final List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements( jsonPath );
sqlAppender.appendSql( "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( '\'' );
}View on GitHub (pinned to fad1729dce)
Solutions
- Inline the path as a string literal: json_value(e.doc, '$.name').
- Build the HQL string with the literal path interpolated - validate the path against a strict pattern (e.g. ^\$[.A-Za-z0-9_\[\]-]*$) to prevent injection.
- Maintain a whitelist of pre-built queries per field and select among them.
- Use a native query where the path can be a real bind parameter.
Example fix
// before - throws: path is a bind parameter
session.createQuery("select json_value(e.doc, :p) from Event e", String.class)
.setParameter("p", "$.name")
// after - literal path
session.createQuery("select json_value(e.doc, '$.name') from Event e", String.class) Defensive patterns
Strategy: fallback
Validate before calling
boolean safe = path.matches("^\$[.A-Za-z0-9_\[\]'-]*$");
if (!safe) throw new IllegalArgumentException("untrusted json path");
String hql = "select json_value(e.doc, '" + path + "') from Event e"; Try / catch
try {
return session.createQuery(hql, String.class).getResultList();
} catch (QueryException e) {
if (e.getMessage().contains("literal json paths")) {
throw new IllegalArgumentException("json path must be a literal: " + path, e);
}
throw e;
} Prevention
- Inline the jsonpath as a literal on SingleStore - never bind it
- Whitelist dynamic paths before interpolating them into HQL
When it happens
Trigger: HQL like: select json_value(e.doc, :path) from Event e with query.setParameter("path", '$.name'). Any parameter expression in the jsonpath argument position triggers it; a string literal '$.name' works fine.
Common situations: Dynamic field extraction where the field name is only known at runtime; generic JSON APIs migrated from Oracle/PostgreSQL dialects; reusing one query text with different paths.
Related errors
- SingleStore json_query only support literal json paths, but
- Can't emulate on error clause on SingleStore
- Can't emulate on empty clause on SingleStore
- JSON path [" + jsonPath + "] uses parameter [" + parameterNa
- CockroachDB json_value only support literal json paths, but
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/25828e487049b34d.
Report an issue: GitHub.