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

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

Source

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

		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
		);
		sqlAppender.appendSql( ' ' );
		sqlAppender.appendSql( definition.name() );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove the ON EMPTY 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 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/640244f0fefc6caf. Report an issue: GitHub.