hibernate/hibernate-orm · error · QueryException
Can't emulate on error clause on SingleStore
Error message
Can't emulate on error clause on SingleStore
What it means
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.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonValueFunction.java:36
/**
* SingleStore json_value function.
*/
public class SingleStoreJsonValueFunction extends JsonValueFunction {
public SingleStoreJsonValueFunction(TypeConfiguration typeConfiguration) {
super( typeConfiguration, true, false );
}
@Override
protected void render(
SqlAppender sqlAppender,
JsonValueArguments arguments,
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.NULL ) {
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() );View on GitHub (pinned to fad1729dce)
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.
Example fix
// before - throws on SingleStore select json_value(e.doc, '$.count' error on error) from Event e // after - default null on error select json_value(e.doc, '$.count') from Event e
Defensive patterns
Strategy: fallback
Validate before calling
// Omit 'on error' - implicit null-on-error is the only supported behavior on SingleStore String hql = "select json_value(e.doc, '$.count') from Event e";
Try / catch
try {
return session.createQuery(hql, String.class).getSingleResult();
} catch (QueryException e) {
if (e.getMessage().contains("on error clause")) {
return null; // emulate in application code
}
throw e;
} Prevention
- Omit ON ERROR in portable HQL
- Validate documents with json_exists when strict error semantics are needed
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Can't emulate on empty clause on SingleStore
- Can't emulate json_objectagg filter clause when using 'null
- Can't emulate on error clause on SingleStore
- Can't emulate on empty clause on SingleStore
- Can't emulate on error clause on CockroachDB
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/be6248822226b591.
Report an issue: GitHub.