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/PostgreSQLJsonQueryFunction.java:44

 */
public class PostgreSQLJsonQueryFunction extends JsonQueryFunction {

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

	@Override
	protected void render(
			SqlAppender sqlAppender,
			JsonQueryArguments arguments,
			ReturnableType<?> returnType,
			SqlAstTranslator<?> walker) {
		// jsonb_path_query functions error by default
		if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonQueryErrorBehavior.ERROR ) {
			throw new QueryException( "Can't emulate on error clause on PostgreSQL" );
		}
		if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonQueryEmptyBehavior.NULL ) {
			throw new QueryException( "Can't emulate on empty clause on PostgreSQL" );
		}

		appendJsonQuery(
				sqlAppender,
				arguments.jsonDocument(),
				arguments.jsonPath(),
				arguments.isJsonType(),
				arguments.wrapMode(),
				arguments.passingClause(),
				walker
		);
	}

	static void appendJsonQuery(SqlAppender sqlAppender, Expression jsonDocument, SqlAstNode jsonPath, boolean isJsonType, JsonQueryWrapMode wrapMode, @Nullable JsonPathPassingClause passingClause, SqlAstTranslator<?> walker) {
		if ( wrapMode == JsonQueryWrapMode.WITH_WRAPPER ) {
			sqlAppender.appendSql( "jsonb_path_query_array(" );
		}
		else if ( wrapMode == JsonQueryWrapMode.WITH_CONDITIONAL_WRAPPER ) {

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