hibernate/hibernate-orm · error · QueryException

Can't emulate on error clause on PostgreSQL

Error message

Can't emulate on error clause on PostgreSQL

What it means

Error "Can't emulate on error clause on PostgreSQL" thrown in hibernate/hibernate-orm.

Source

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

			if ( isBinary ) {
				sqlAppender.appendSql( "decode(" );
			}
			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

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove the ON ERROR clause for PostgreSQL.

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


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