hibernate/hibernate-orm · error · QueryException

Can't emulate null on error clause on PostgreSQL

Error message

Can't emulate null on error clause on PostgreSQL

What it means

Validation guard at the start of PostgreSQL json_table rendering: the query asked for 'null on error' behavior. PostgreSQL has no native json_table, and Hibernate's emulation via jsonb functions cannot suppress errors into nulls for the whole table, so this combination is rejected at translation time with a QueryException. Remove the null-on-error clause or use a database with native json_table (e.g. Oracle/Db2).

Solutions

  1. Remove the NULL 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 null 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 null on error clause on PostgreSQL.


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

Appendix: source

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

/**
 * PostgreSQL json_table function.
 */
public class PostgreSQLJsonTableFunction extends JsonTableFunction {

	public PostgreSQLJsonTableFunction(TypeConfiguration typeConfiguration) {
		super( typeConfiguration );
	}

	@Override
	protected void renderJsonTable(
			SqlAppender sqlAppender,
			JsonTableArguments arguments,
			AnonymousTupleTableGroupProducer tupleType,
			String tableIdentifierVariable,
			SqlAstTranslator<?> walker) {
		if ( arguments.errorBehavior() == JsonTableErrorBehavior.NULL ) {
			throw new QueryException( "Can't emulate null on error clause on PostgreSQL" );
		}
		sqlAppender.appendSql( "(select" );

		renderColumns( sqlAppender, arguments.columnsClause(), 0, walker );

		sqlAppender.appendSql( " from jsonb_path_query(" );

		final boolean needsCast = !arguments.isJsonType() && AbstractSqlAstTranslator.isParameter( arguments.jsonDocument() );
		if ( needsCast ) {
			sqlAppender.appendSql( "cast(" );
		}
		arguments.jsonDocument().accept( walker );
		if ( needsCast ) {
			sqlAppender.appendSql( " as jsonb)" );
		}
		final SqlAstNode jsonPath = arguments.jsonPath();
		if ( jsonPath != null ) {
			sqlAppender.appendSql( ',' );

View on GitHub (pinned to fad1729dce)