hibernate/hibernate-orm · error · QueryException

Can't emulate on empty clause on PostgreSQL

Error message

Can't emulate on empty clause on PostgreSQL

What it means

Guard in the PostgreSQL json_value emulation: an 'on empty' behavior other than the default was requested. PostgreSQL lacks native json_value, so Hibernate emulates it with jsonb operators, and the generated SQL cannot express on-empty handling, so any non-default empty-behavior clause is rejected with a QueryException at render time. Drop the on-empty clause or rely on the default behavior.

Solutions

  1. Remove the ON EMPTY clause for PostgreSQL.
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 empty clause on PostgreSQL.

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 empty clause on PostgreSQL.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/cefdf1d832ea6207. Report an issue: GitHub.

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/PostgreSQLJsonValueFunction.java:65

			super.render( sqlAppender, arguments, returnType, walker );
			// PostgreSQL unfortunately renders `t`/`f` for JSON booleans instead of `true`/`false` like every other DB.
			// To work around this, extract the jsonb node directly and then use the `#>>` operator to unquote values
			// Also see https://stackoverflow.com/questions/79483975/postgresql-json-value-boolean-behavior
			if ( isString( arguments.returningType() ) ) {
				// Unquote the value
				sqlAppender.appendSql( "#>>'{}'" );
			}
			else if ( isBinary ) {
				sqlAppender.appendSql( ",'hex')" );
			}
		}
		else {
			// jsonb_path_query_first errors by default
			if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.ERROR ) {
				throw new QueryException( "Can't emulate on error clause on PostgreSQL" );
			}
			if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {
				throw new QueryException( "Can't emulate on empty clause on PostgreSQL" );
			}

			appendJsonValue(
					sqlAppender,
					arguments.jsonDocument(),
					arguments.jsonPath(),
					arguments.isJsonType(),
					arguments.returningType(),
					arguments.passingClause(),
					walker
			);
		}
	}

	@Override
	protected void renderReturningClause(SqlAppender sqlAppender, JsonValueArguments arguments, SqlAstTranslator<?> walker) {
		// See #render for an explanation of this behavior
		if ( supportsStandard && isString( arguments.returningType() ) ) {

View on GitHub (pinned to fad1729dce)