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/PostgreSQLJsonExistsFunction.java:36

/**
 * PostgreSQL json_exists function.
 */
public class PostgreSQLJsonExistsFunction extends JsonExistsFunction {

	public PostgreSQLJsonExistsFunction(TypeConfiguration typeConfiguration) {
		super( typeConfiguration, true, true );
	}

	@Override
	protected void render(
			SqlAppender sqlAppender,
			JsonExistsArguments arguments,
			ReturnableType<?> returnType,
			SqlAstTranslator<?> walker) {
		// jsonb_path_exists errors by default
		if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonExistsErrorBehavior.ERROR ) {
			throw new QueryException( "Can't emulate on error clause on PostgreSQL" );
		}
		appendJsonExists( sqlAppender, walker, arguments.jsonDocument(), arguments.jsonPath(), arguments.passingClause() );
	}

	static void appendJsonExists(SqlAppender sqlAppender, SqlAstTranslator<?> walker, Expression jsonDocument, Expression jsonPath, @Nullable JsonPathPassingClause passingClause) {
		sqlAppender.appendSql( "jsonb_path_exists(" );
		jsonDocument.accept( walker );
		sqlAppender.appendSql( ',' );
		jsonPath.accept( walker );
		if ( passingClause != null ) {
			sqlAppender.append( ",jsonb_build_object" );
			char separator = '(';
			for ( Map.Entry<String, Expression> entry : passingClause.getPassingExpressions().entrySet() ) {
				sqlAppender.append( separator );
				sqlAppender.appendSingleQuoteEscapedString( entry.getKey() );
				sqlAppender.append( ',' );
				entry.getValue().accept( walker );
				separator = ',';

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/1b18216353ff0912. Report an issue: GitHub.