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

PostgreSQLJsonTableFunction's value column definition (renderJsonValueColumnDefinition) cannot emulate an explicit non-default on-error behavior for jsonb extraction; the requested error clause has no PostgreSQL translation and rendering throws.

Solutions

  1. Remove the ON ERROR 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 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/aeb36af7d118fe59. Report an issue: GitHub.

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/PostgreSQLJsonTableFunction.java:143

	@Override
	protected int renderJsonNestedColumnDefinition(SqlAppender sqlAppender, JsonTableNestedColumnDefinition definition, int clauseLevel, SqlAstTranslator<?> walker) {
		return renderColumns( sqlAppender, definition.columns(), clauseLevel, walker );
	}

	@Override
	protected void renderJsonOrdinalityColumnDefinition(SqlAppender sqlAppender, JsonTableOrdinalityColumnDefinition definition, int clauseLevel, SqlAstTranslator<?> walker) {
		sqlAppender.appendSql( 't' );
		sqlAppender.appendSql( clauseLevel );
		sqlAppender.appendSql( ".i " );
		sqlAppender.appendSql( definition.name() );
	}

	@Override
	protected void renderJsonValueColumnDefinition(SqlAppender sqlAppender, JsonTableValueColumnDefinition definition, int clauseLevel, SqlAstTranslator<?> walker) {
		// jsonb_path_query_first errors by default
		if ( definition.errorBehavior() != null && definition.errorBehavior() != JsonValueErrorBehavior.ERROR ) {
			throw new QueryException( "Can't emulate on error clause on PostgreSQL" );
		}
		if ( definition.emptyBehavior() != null && definition.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {
			throw new QueryException( "Can't emulate on empty clause on PostgreSQL" );
		}
		final String jsonPath = definition.jsonPath() == null
				? "$." + definition.name()
				: definition.jsonPath();
		PostgreSQLJsonValueFunction.appendJsonValue(
				sqlAppender,
				new ClauseLevelDocumentExpression( clauseLevel ),
				new QueryLiteral<>(
						jsonPath,
						walker.getSessionFactory().getTypeConfiguration().getBasicTypeForJavaType( String.class )
				),
				true,
				definition.type(),
				null,
				walker

View on GitHub (pinned to fad1729dce)