{"record":{"id":"91ff231a371d0f68","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-non-simple-json-path-expression-js","errorCode":null,"errorMessage":"Can't emulate non-simple json path expression: {jsonPath}","messagePattern":"Can't emulate non-simple json path expression: (.+?)","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/json/JsonPathHelper.java","lineNumber":47,"sourceCode":"\t\t\t\tstartIndex = 2;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfinal int bracketEndIndex = jsonPath.indexOf( ']' );\n\t\t\t\tparseBracket( jsonPath, 1, bracketEndIndex, jsonPathElements );\n\t\t\t\tstartIndex = bracketEndIndex + 2;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\twhile ( ( dotIndex = jsonPath.indexOf( '.', startIndex ) ) != -1 ) {\n\t\t\t\t\tparseAttribute( jsonPath, startIndex, dotIndex, jsonPathElements );\n\t\t\t\t\tstartIndex = dotIndex + 1;\n\t\t\t\t}\n\t\t\t\tif ( startIndex < jsonPath.length() ) {\n\t\t\t\t\tparseAttribute( jsonPath, startIndex, jsonPath.length(), jsonPathElements );\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (Exception ex) {\n\t\t\t\tthrow new QueryException( \"Can't emulate non-simple json path expression: \" + jsonPath, ex );\n\t\t\t}\n\t\t}\n\t\treturn jsonPathElements;\n\t}\n\n\tpublic static void appendJsonPathConcatPassingClause(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tExpression jsonPathExpression,\n\t\t\tJsonPathPassingClause passingClause, SqlAstTranslator<?> walker) {\n\t\tappendJsonPathConcatenatedPassingClause( sqlAppender, jsonPathExpression, passingClause, walker, \"concat\", \",\" );\n\t}\n\n\tpublic static void appendJsonPathDoublePipePassingClause(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tExpression jsonPathExpression,\n\t\t\tJsonPathPassingClause passingClause,\n\t\t\tSqlAstTranslator<?> walker) {\n\t\tappendJsonPathConcatenatedPassingClause( sqlAppender, jsonPathExpression, passingClause, walker, \"\", \"||\" );","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/json/JsonPathHelper.java#L29-L65","documentation":"The emulation parses only simple path segments: attributes joined by dots and bracket indexes. parseAttribute and parseBracket throw on wildcards, ranges like [1 to 3], filter expressions like ?(@.x), or non-numeric bracket content. The catch block wraps any such failure in this QueryException.","triggerScenarios":"A query passes a path with advanced SQL/JSON syntax, for example '$.items[*]', '$.items[1 to 3]', or '$.items?(@.price > 10)', on a dialect that uses path emulation.","commonSituations":"Paths validated against PostgreSQL or Oracle behavior, where richer path grammar is native. Business requirements that ask for array slices and filters inside the path.","solutions":["Rewrite the path with explicit simple segments: replace '$.items[*]' with a set-based query over json_table.","Move filtering and slicing into HQL/SQL predicates instead of the path expression.","Use a native query for statements that need wildcards, ranges, or filter expressions.","Keep paths to the supported forms: '$.attr.attr2' and '$.attr[0]' (plus [$param] with a passing clause)."],"exampleFix":"// before\nselect json_query(e.doc, '$.items[*].name') from Entity e\n\n// after\nselect t.name from Entity e, json_table(e.doc, '$.items' columns(name varchar path '$.name')) t","handlingStrategy":"validation","validationCode":"// Only simple segments survive emulation: $, .attr, [n], [$name].\nstatic final java.util.regex.Pattern SIMPLE =\n    java.util.regex.Pattern.compile(\"^\\\\$(\\\\.[A-Za-z_][\\\\w]*(\\\\[\\\\d+]|\\\\[\\\\$\\\\w+])?)*$\");\n\nstatic boolean isEmulatablePath(String path) {\n    return SIMPLE.matcher(path).matches();\n}\n\nif (!isEmulatablePath(path)) {\n    throw new UnsupportedOperationException(\"JSON path needs native dialect support: \" + path);\n}","typeGuard":"static boolean isSimpleJsonPath(String path) {\n    return path != null && java.util.regex.Pattern\n        .compile(\"^\\\\$(\\\\.[A-Za-z_][\\\\w]*(\\\\[\\\\d+]|\\\\[\\\\$\\\\w+])?)*$\")\n        .matcher(path).matches();\n}","tryCatchPattern":"try {\n    return session.createQuery(hql, String.class).getSingleResult();\n} catch (org.hibernate.QueryException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"non-simple json path\")) {\n        // Split the query: use json_table + predicates instead of an advanced path.\n        throw new UnsupportedOperationException(\"Rewrite the path with json_table or run native SQL\", e);\n    }\n    throw e;\n}","preventionTips":["Restrict path constants to '$.attr' and '[n]' forms for portable HQL.","Express wildcards and slices with json_table plus WHERE predicates.","Add a lint check for advanced path syntax in query constants."],"tags":["hibernate","json","json-path","path-parsing","dialect-emulation"],"backgroundTag":"json-path-not-simple-enough","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}