hibernate/hibernate-orm · error · QueryException
SingleStore json_exists only support literal json paths, but
Error message
SingleStore json_exists only support literal json paths, but got {} What it means
SingleStore's json_match_any_exists requires the JSON path to be decomposed into literal path constants, so the path argument must be a string literal. render() calls getLiteralValue on the path expression; a bind parameter or computed expression fails, and the resulting QueryException echoes the offending path expression.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonExistsFunction.java:41
public SingleStoreJsonExistsFunction(TypeConfiguration typeConfiguration) {
super( typeConfiguration, true, false );
}
@Override
protected void render(
SqlAppender sqlAppender,
JsonExistsArguments arguments,
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonExistsErrorBehavior.ERROR ) {
throw new QueryException( "Can't emulate on error clause on SingleStore" );
}
final String jsonPath;
try {
jsonPath = walker.getLiteralValue( arguments.jsonPath() );
}
catch (Exception ex) {
throw new QueryException( "SingleStore json_exists only support literal json paths, but got " + arguments.jsonPath() );
}
final List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements( jsonPath );
sqlAppender.appendSql( "json_match_any_exists(" );
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 jsonParameterIndexAccess) {
final String parameterName = jsonParameterIndexAccess.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_exists(e.doc, 'items[0]')
- Concatenate a validated, whitelisted path into the HQL string in Java (mind injection)
- Switch to a native query if the path must stay dynamic
- Model frequently queried attributes as real columns instead of ad-hoc JSON paths
Example fix
// before
em.createQuery("select e from E e where json_exists(e.doc, :path)")
.setParameter("path", "items[0]");
// after: literal path in the query string
em.createQuery("select e from E e where json_exists(e.doc, 'items[0]')"); Defensive patterns
Strategy: validation
Validate before calling
// The path must be a string literal; never bind it as a parameter on SingleStore
static String literalJsonPath(String path, int index) {
// build from validated components only — no user input concatenation
if (!path.matches("[A-Za-z0-9_.\\[\\]-]*")) throw new IllegalArgumentException("bad path");
return path;
} Try / catch
try {
return em.createQuery("select e from E e where json_exists(e.doc, :path)")
.setParameter("path", p).getResultList();
} catch (QueryException e) {
if (e.getMessage() != null && e.getMessage().contains("literal json paths")) {
// inline the path literal (validated) into the HQL and retry
}
throw e;
} Prevention
- On SingleStore, inline JSON paths as literals instead of binding parameters
- Whitelist-validate any path built dynamically before embedding it in HQL
- Consider extracting hot JSON attributes into columns to avoid dynamic paths
When it happens
Trigger: HQL `json_exists(e.doc, :path)` or a computed path like `json_exists(e.doc, concat('items[', i, ']'))` on SingleStoreDialect.
Common situations: Generic DAO layers that bind paths as parameters to plan-cache queries; multi-dialect code where PostgreSQL accepts parameterized paths via passing.
Related errors
- JSON path [{}] uses parameter [{}] that is not passed
- JSON path [{}] uses parameter [{}] that is not passed
- SingleStore json_array_insert function requires at least one
- SingleStore json_array_insert function last path parameter m
- JSON path [{}] uses parameter [{}] that is not passed
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/42a56c6800f71adc.
Report an issue: GitHub.