hibernate/hibernate-orm · error · IllegalArgumentException

Empty selections passed to criteria query typed as Object

Error message

Empty selections passed to criteria query typed as Object

What it means

Validation in getResultSelection for a criteria query typed as Object: multiselect received an empty selection array/list, leaving nothing from which to infer the Object[] result shape.

Solutions

  1. Provide at least one selection to the criteria query (e.g. criteria.select(root) or criteria.multiselect(...)).
  2. If you intend a compound result, declare the query as Tuple/Object[] instead of Object and pass multiple selections.
  3. Check code paths that build the selection list dynamically and make sure the list is not empty before calling multiselect.
Defensive patterns

Strategy: validation

When it happens

Trigger: multiselect() is called with an empty selection list on a CriteriaQuery typed as Object, so no result shape can be inferred.

Common situations: Passing an empty or conditionally-built selection list that ended up empty; provide at least one selection or use Object[].class.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/AbstractSqmSelectQuery.java:525

		return object instanceof AbstractSqmSelectQuery<?> that
			&& Objects.equals( this.resultType, that.resultType ) // for performance!
			&& this.sqmQueryPart.isCompatible( that.sqmQueryPart )
			&& SqmCacheable.areCompatible( this.cteStatements, that.cteStatements );
	}

	@Override
	public int cacheHashCode() {
		int result = SqmCacheable.cacheHashCode( cteStatements );
		result = 31 * result + sqmQueryPart.cacheHashCode();
		return result;
	}

	@SuppressWarnings("unchecked")
	protected Selection<? extends T> getResultSelection(Selection<?>[] selections) {
		final var resultType = getResultType();
		if ( resultType == Object.class ) {
			return switch ( selections.length ) {
				case 0 -> throw new IllegalArgumentException( "Empty selections passed to criteria query typed as Object" );
				case 1 -> (Selection<? extends T>) selections[0];
				default -> (Selection<? extends T>) nodeBuilder().array( selections );
			};
		}
		else if ( Tuple.class.isAssignableFrom( resultType ) ) {
			return (Selection<? extends T>) nodeBuilder().tuple( selections );
		}
		else if ( resultType.isArray() ) {
			return nodeBuilder().array( resultType, selections );
		}
		else {
			return nodeBuilder().construct( resultType, selections );
		}
	}

}

View on GitHub (pinned to fad1729dce)