hibernate/hibernate-orm · error · IllegalArgumentException

Fetch clause may not be null

Error message

Fetch clause may not be null

What it means

Error "Fetch clause may not be null" thrown in hibernate/hibernate-orm.

Source

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

	public void setOffsetExpression(@Nullable SqmExpression<? extends Number> offsetExpression) {
		if ( offsetExpression != null ) {
			offsetExpression.applyInferableType( nodeBuilder.getIntegerType() );
		}
		this.offsetExpression = offsetExpression;
	}

	public void setFetchExpression(@Nullable SqmExpression<? extends Number> fetchExpression) {
		setFetchExpression( fetchExpression, FetchClauseType.ROWS_ONLY );
	}

	public void setFetchExpression(@Nullable SqmExpression<? extends Number> fetchExpression, FetchClauseType fetchClauseType) {
		if ( fetchExpression == null ) {
			this.fetchExpression = null;
			this.fetchClauseType = FetchClauseType.ROWS_ONLY;
		}
		else {
			if ( fetchClauseType == null ) {
				throw new IllegalArgumentException( "Fetch clause may not be null" );
			}
			fetchExpression.applyInferableType( nodeBuilder.getIntegerType() );
			this.fetchExpression = fetchExpression;
			this.fetchClauseType = fetchClauseType;
		}
	}

	@Override
	public FetchClauseType getFetchClauseType() {
		return fetchClauseType;
	}

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// JPA

	@Override
	@Nonnull
	public List<SqmSortSpecification> getSortSpecifications() {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass a non-null FetchClauseType to the fetch clause API (e.g. FetchClauseType.ROWS_ONLY, ROWS_FIRST, ROWS_WITH_TIES).
  2. If no fetch clause is needed, do not call the fetch method at all instead of passing null.

When it happens

Trigger: A fetch clause is set on a query part while JPA compliance checking rejects a null/absent fetch value.

Common situations: Calling setFetchClause with a null expression; supply a valid fetch expression.


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