hibernate/hibernate-orm · error · QueryException
Can't emulate on error clause on SQL server
Error message
Can't emulate on error clause on SQL server
What it means
SQLServerJsonQueryFunction maps json_query to openjson, which errors by default; an explicit JsonQueryErrorBehavior other than ERROR has no SQL Server emulation and rendering the on-error clause throws.
Solutions
- Remove the ON ERROR clause for SQL Server.
Defensive patterns
Strategy: fallback
When it happens
Trigger: Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: Can't emulate on error clause on SQL server.
Common situations: Common when running against a database whose dialect lacks this capability, when a mapping or HQL/Criteria query requests unsupported functionality, or when the wrong dialect is configured for the database in use. Error: Can't emulate on error clause on SQL server.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/a78db901b1f18852.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/SQLServerJsonQueryFunction.java:36
/**
* SQL Server json_query function.
*/
public class SQLServerJsonQueryFunction extends JsonQueryFunction {
public SQLServerJsonQueryFunction(TypeConfiguration typeConfiguration) {
super( typeConfiguration, true, false );
}
@Override
protected void render(
SqlAppender sqlAppender,
JsonQueryArguments arguments,
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
// openjson errors by default
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonQueryErrorBehavior.ERROR ) {
throw new QueryException( "Can't emulate on error clause on SQL server" );
}
final List<JsonPathHelper.JsonPathElement> jsonPathElements = JsonPathHelper.parseJsonPathElements(
walker.getLiteralValue( arguments.jsonPath() )
);
if ( arguments.emptyBehavior() == JsonQueryEmptyBehavior.EMPTY_ARRAY
|| arguments.emptyBehavior() == JsonQueryEmptyBehavior.EMPTY_OBJECT ) {
sqlAppender.appendSql( "coalesce(" );
}
render( sqlAppender, arguments, jsonPathElements, jsonPathElements.size() - 1, walker );
if ( arguments.emptyBehavior() == JsonQueryEmptyBehavior.EMPTY_ARRAY ) {
sqlAppender.appendSql( ",'[]')" );
}
else if ( arguments.emptyBehavior() == JsonQueryEmptyBehavior.EMPTY_OBJECT ) {
sqlAppender.appendSql( ",'{}')" );
}
}
private void render(View on GitHub (pinned to fad1729dce)