{"record":{"id":"be6248822226b591","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-on-error-clause-on-singlestore-be6248","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/SingleStoreJsonValueFunction.java","lineNumber":36,"sourceCode":"\n/**\n * SingleStore json_value function.\n */\npublic class SingleStoreJsonValueFunction extends JsonValueFunction {\n\n\tpublic SingleStoreJsonValueFunction(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\tJsonValueArguments arguments,\n\t\t\tReturnableType<?> returnType,\n\t\t\tSqlAstTranslator<?> walker) {\n\n\t\tif ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.NULL ) {\n\t\t\tthrow new QueryException( \"Can't emulate on error clause on SingleStore\" );\n\t\t}\n\t\tif ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {\n\t\t\tthrow new QueryException( \"Can't emulate on empty clause on SingleStore\" );\n\t\t}\n\t\tif ( arguments.returningType() != null ) {\n\t\t\tif ( arguments.returningType().getJdbcMapping().getJdbcType().isBoolean() ) {\n\t\t\t\tsqlAppender.append( \"case \" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsqlAppender.append( \"cast(\" );\n\t\t\t}\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_value only support literal json paths, but got \" + arguments.jsonPath() );","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonValueFunction.java#L18-L54","documentation":"SingleStore's json_value emulation (json_extract_string plus optional cast) always returns null when the document/path is invalid, so the dialect only supports the default 'null on error' behavior. If the HQL json_value() explicitly asks for 'error on error' or 'default <expr> on error', SingleStoreJsonValueFunction.render throws this QueryException because raising a SQL error (or producing a default value) cannot be emulated.","triggerScenarios":"HQL like: select json_value(e.doc, '$.x' error on error) from Event e, or json_value(e.doc, '$.x' default 'n/a' on error). The check is arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.NULL (note JsonValueErrorBehavior has ERROR, NULL, and defaultOnError(expr) variants).","commonSituations":"Queries written for the SQL standard default (ERROR ON ERROR) or using DEFAULT ... ON ERROR; strict validation queries that want an exception on malformed JSON; migrating to SingleStore.","solutions":["Drop the 'on error' clause - the implicit null-on-error behavior is what SingleStore provides.","If you must detect bad documents, validate with json_exists or a separate well-formedness check and branch in Java.","Use 'null on error' explicitly when the query is shared with other dialects.","Fall back to native SQL if raising on error is mandatory."],"exampleFix":"// before - throws on SingleStore\nselect json_value(e.doc, '$.count' error on error) from Event e\n\n// after - default null on error\nselect json_value(e.doc, '$.count') from Event e","handlingStrategy":"fallback","validationCode":"// Omit 'on error' - implicit null-on-error is the only supported behavior on SingleStore\nString hql = \"select json_value(e.doc, '$.count') from Event e\";","typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(hql, String.class).getSingleResult();\n} catch (QueryException e) {\n    if (e.getMessage().contains(\"on error clause\")) {\n        return null; // emulate in application code\n    }\n    throw e;\n}","preventionTips":["Omit ON ERROR in portable HQL","Validate documents with json_exists when strict error semantics are needed"],"tags":["singlestore","json","json-value","hql","sql-dialect","query-exception"],"backgroundTag":"unsupported-sql-dialect-feature","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}