hibernate/hibernate-orm · error · IllegalArgumentException

Key definition must not null

Error message

Key definition must not null

What it means

Thrown by Page.keyedBy(Order) when the caller passes a null key definition while requesting a key-based page specification. A key-based pager requires a non-null Order that defines the total ordering used to seek through results, so a null argument is rejected immediately before a KeyedPage can be built.

Solutions

  1. Provide a non-null key definition for keyset pagination.
  2. Build the Page with a valid key reference.
Defensive patterns

Strategy: validation

When it happens

Trigger: A runtime precondition of the Hibernate API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/Page.java:149

		return new Page( size, number-1 );
	}

	public Page first() {
		return first( size );
	}

	/**
	 * Obtain a {@linkplain KeyedPage key-based specification} of this page.
	 *
	 * @param keyDefinition an {@link Order} object defining a total order
	 *                      on the result set
	 * @return a {@link KeyedPage} representing this page
	 *
	 * @since 6.5
	 */
	public <R> KeyedPage<R> keyedBy(Order<? super R> keyDefinition) {
		if ( keyDefinition == null )  {
			throw new IllegalArgumentException("Key definition must not null");
		}
		return new KeyedPage<>( List.of(keyDefinition), this );
	}

	/**
	 * Obtain a {@linkplain KeyedPage key-based specification} of this page.
	 *
	 * @param keyDefinition a list of {@link Order} objects defining a total
	 *                      order on the result set
	 * @return a {@link KeyedPage} representing this page
	 *
	 * @since 6.5
	 */
	public <R> KeyedPage<R> keyedBy(List<Order<? super R>> keyDefinition) {
		if ( keyDefinition == null || keyDefinition.isEmpty() )  {
			throw new IllegalArgumentException("Key definition must not be empty or null");
		}
		return new KeyedPage<>( keyDefinition, this );

View on GitHub (pinned to fad1729dce)