hibernate/hibernate-orm · error · IllegalArgumentException

Not a SqmSelectStatement

Error message

Not a SqmSelectStatement

What it means

Error "Not a SqmSelectStatement" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/criteria/CriteriaDefinition.java:153

		query = ((SqmSelectStatement<R>) template.query)
				.copy( SqmCopyContext.simpleContext() );
	}

	/**
	 * Construct a new {@code CriteriaDefinition} based on the given
	 * {@code CriteriaDefinition}. This overload permits changing the
	 * query return type. It is expected that {@link #select} be called
	 * to rewrite the selection list.
	 *
	 * @param template the original query
	 * @param resultType the new return type
	 *
	 * @since 7.0
	 */
	public CriteriaDefinition(CriteriaDefinition<?> template, Class<R> resultType) {
		super( template.getCriteriaBuilder() );
		if ( !(template.query instanceof SqmSelectStatement<?> selectStatement) ) {
			throw new IllegalArgumentException( "Not a SqmSelectStatement" );
		}
		query = selectStatement.createCopy( SqmCopyContext.simpleContext(), resultType );
	}

	public CriteriaDefinition(SessionFactory factory, Class<R> resultType) {
		super( factory.getCriteriaBuilder() );
		query = createQuery( resultType );
	}

	public CriteriaDefinition(SessionFactory factory, Class<R> resultType, String baseHql) {
		super( factory.getCriteriaBuilder() );
		query = createQuery( baseHql, resultType );
	}

	public CriteriaDefinition(SessionFactory factory, CriteriaQuery<R> baseQuery) {
		super( factory.getCriteriaBuilder() );
		query = (JpaCriteriaQuery<R>) baseQuery;
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Cast only select statements to SqmSelectStatement.
  2. Check the statement type before casting.

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/3aab38dd1b55db12. Report an issue: GitHub.