{"record":{"id":"3b5ae362e89cb239","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-on-error-clause-on-singlestore","errorCode":null,"errorMessage":"Can't emulate on error clause on SingleStore","messagePattern":"Can't emulate on error clause on SingleStore","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonExistsFunction.java","lineNumber":34,"sourceCode":"import org.hibernate.type.spi.TypeConfiguration;\n\n/**\n * SingleStore json_exists function.\n */\npublic class SingleStoreJsonExistsFunction extends JsonExistsFunction {\n\n\tpublic SingleStoreJsonExistsFunction(TypeConfiguration typeConfiguration) {\n\t\tsuper( typeConfiguration, true, false );\n\t}\n\n\t@Override\n\tprotected void render(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tJsonExistsArguments arguments,\n\t\t\tReturnableType<?> returnType,\n\t\t\tSqlAstTranslator<?> walker) {\n\t\tif ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonExistsErrorBehavior.ERROR ) {\n\t\t\tthrow new QueryException( \"Can't emulate on error clause on SingleStore\" );\n\t\t}\n\t\tfinal String jsonPath;\n\t\ttry {\n\t\t\tjsonPath = walker.getLiteralValue( arguments.jsonPath() );\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new QueryException( \"SingleStore json_exists only support literal json paths, but got \" + arguments.jsonPath() );\n\t\t}\n\t\tfinal List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements( jsonPath );\n\t\tsqlAppender.appendSql( \"json_match_any_exists(\" );\n\t\targuments.jsonDocument().accept( walker );\n\t\tfor ( JsonPathHelper.JsonPathElement pathElement : jsonPathElements ) {\n\t\t\tsqlAppender.appendSql( ',' );\n\t\t\tif ( pathElement instanceof JsonPathHelper.JsonAttribute attribute ) {\n\t\t\t\tsqlAppender.appendSingleQuoteEscapedString( attribute.attribute() );\n\t\t\t}\n\t\t\telse if ( pathElement instanceof JsonPathHelper.JsonParameterIndexAccess jsonParameterIndexAccess) {\n\t\t\t\tfinal String parameterName = jsonParameterIndexAccess.parameterName();","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonExistsFunction.java#L16-L52","documentation":"Standard SQL json_exists can specify an error behavior (TRUE/FALSE/UNKNOWN/ERROR ON ERROR). SingleStore's json_match_any_exists emulation has no way to suppress or convert path errors, so render() accepts only the default ERROR ON ERROR (or no clause at all) and throws QueryException for any other behavior.","triggerScenarios":"HQL `json_exists(e.doc, 'a.b' false on error)` (also `true on error` / `unknown on error`) on SingleStoreDialect; omitting the clause works.","commonSituations":"Queries ported from Oracle/PostgreSQL where 'false on error' guards malformed documents; defensive JSON probing written against more permissive backends.","solutions":["Remove the 'on error' clause and accept the default ERROR behavior","Pre-filter invalid JSON documents (native is_json-style check) before running json_exists","Catch the resulting database error in Java and treat it as a false/unknown result","Run the existence check as a native query that handles errors explicitly"],"exampleFix":"// before\nselect e from E e where json_exists(e.doc, 'a.b' false on error)\n\n// after\nselect e from E e where json_exists(e.doc, 'a.b')","handlingStrategy":"validation","validationCode":"// Only the default ERROR ON ERROR is emulatable on SingleStore\nstatic boolean jsonExistsOnErrorOk(String onErrorClause, Dialect d) {\n    return !(d instanceof SingleStoreDialect)\n        || onErrorClause == null || onErrorClause.isBlank();\n}","typeGuard":null,"tryCatchPattern":"try {\n    return em.createQuery(hql).getResultList(); // '... false on error'\n} catch (QueryException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"on error clause\")) {\n        // strip the on-error clause; catch the JDBC error in Java as the fallback behavior\n    }\n    throw e;\n}","preventionTips":["Do not port 'on error' clauses to SingleStore queries; default to ERROR behavior","Validate malformed documents once at write time instead of tolerating errors at read time","Wrap json_exists calls with a Java-side try/catch that maps SQL errors to false/unknown"],"tags":["hibernate","singlestore","json-exists","on-error-clause"],"backgroundTag":"json-exists-on-error-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}