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 has no ON ERROR clause for json_query, so the community dialect can only render the default behavior (ERROR). When an HQL json_query() specifies any other error behavior - 'null on error', 'empty array on error', or 'empty object on error' - SingleStoreJsonQueryFunction.render throws this QueryException during SQL translation because there is no way to emulate swallowing or rewriting errors in json_extract_string.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/function/json/SingleStoreJsonQueryFunction.java:36
import org.hibernate.type.spi.TypeConfiguration;
/**
* SingleStore json_query function.
*/
public class SingleStoreJsonQueryFunction extends JsonQueryFunction {
public SingleStoreJsonQueryFunction(TypeConfiguration typeConfiguration) {
super( typeConfiguration, true, false );
}
@Override
protected void render(
SqlAppender sqlAppender,
JsonQueryArguments arguments,
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonQueryErrorBehavior.ERROR ) {
throw new QueryException( "Can't emulate on error clause on SingleStore" );
}
if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonQueryEmptyBehavior.NULL ) {
throw new QueryException( "Can't emulate on empty clause on SingleStore" );
}
else {
final String jsonPath;
try {
jsonPath = walker.getLiteralValue( arguments.jsonPath() );
}
catch (Exception ex) {
throw new QueryException( "SingleStore json_query only support literal json paths, but got " + arguments.jsonPath() );
}
final List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements( jsonPath );
final JsonQueryWrapMode wrapMode = arguments.wrapMode();
final DecorationMode decorationMode = determineDecorationMode( wrapMode );
if ( decorationMode == DecorationMode.WRAP ) {
sqlAppender.appendSql( "concat('['," );
}View on GitHub (pinned to fad1729dce)
Solutions
- Drop the 'on error' clause from the HQL json_query call - the default (error) is exactly what SingleStore does.
- Keep the clause but only as 'error on error' (equivalent to the default) for cross-dialect portability.
- Pre-validate the document with json_exists() (or a try/catch around query execution) and branch in Java instead of asking the database to swallow errors.
- Fall back to a native query wrapping json_extract_string in logic that returns null on error.
Example fix
// before - throws on SingleStore select json_query(e.doc, '$.tags' null on error) from Event e // after - default error behavior, handle null result in Java if path misses select json_query(e.doc, '$.tags') from Event e
Defensive patterns
Strategy: fallback
Validate before calling
// Keep json_query clauses dialect-portable: omit 'on error' entirely (default ERROR is supported everywhere) String hql = "select json_query(e.doc, '$.tags') 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 'null on error' in application code
}
throw e;
} Prevention
- Omit ON ERROR/ON EMPTY clauses unless a dialect matrix confirms support
- Centralize JSON queries so unsupported-clause errors surface in one place
- Add integration tests that run JSON queries against the production dialect
When it happens
Trigger: HQL like: select json_query(e.doc, '$.tags' null on error) from Event e (also triggers with 'empty array on error' / 'empty object on error'). The check is arguments.errorBehavior() != null && arguments.errorBehavior() != JsonQueryErrorBehavior.ERROR, i.e. any explicit non-default error behavior.
Common situations: Defensive JSON queries written for PostgreSQL/Oracle that ask for NULL instead of an exception on malformed documents; migrating an application to SingleStore (via the hibernate-community-dialects SingleStoreDialect) and re-running existing HQL; shared query libraries used across multiple databases.
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 H2
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/42c18944d22534d0.
Report an issue: GitHub.