hibernate/hibernate-orm · error · IllegalArgumentException

Max results cannot be negative

Error message

Max results cannot be negative

What it means

Error "Max results cannot be negative" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java:433

		return this;
	}

	@Override
	@Nonnull
	public SelectionQueryImplementor<R> setFirstResult(int startPosition) {
		session.checkOpen();
		if ( startPosition < 0 ) {
			throw new IllegalArgumentException( "First result cannot be negative" );
		}
		queryOptions.getLimit().setFirstRow( startPosition );
		return this;
	}

	@Override
	@Nonnull
	public SelectionQueryImplementor<R> setMaxResults(int maxResults) {
		if ( maxResults < 0 ) {
			throw new IllegalArgumentException( "Max results cannot be negative" );
		}
		session.checkOpen();
		queryOptions.getLimit().setMaxRows( maxResults );
		return this;
	}

	@Override
	public SelectionQueryImplementor<R> setPage(Page page) {
		setMaxResults( page.getMaxResults() );
		setFirstResult( page.getFirstResult() );
		return this;
	}

	@Override
	@Nullable
	public LockModeType getLockMode() {
		session.checkOpen( false );
		//noinspection removal

View on GitHub (pinned to fad1729dce)

Solutions

  1. setMaxResults() was given a negative value. Pass a non-negative maximum (or leave it unset for unlimited).

When it happens

Trigger: A negative pagination bound is set: Max results cannot be negative

Common situations: Calling setFirstResult()/setMaxResults() with a negative value.


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