hibernate/hibernate-orm · error · IllegalSelectQueryException

Expecting a selection query, but found '{}'

Error message

Expecting a selection query, but found '{}'

What it means

Error "Expecting a selection query, but found '{}'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java:346

	 */
	@Nonnull
	private static <T> SqmSelectStatement<T> resolveSqmTree(
			@Nonnull String hql,
			@Nonnull Class<T> resultType,
			@Nonnull QueryEngine queryEngine) {
		final var hqlInterpretation =
				queryEngine.getInterpretationCache()
						.resolveHqlInterpretation( hql, resultType, queryEngine.getHqlTranslator() );
		if ( SqmUtil.isSelect( hqlInterpretation.getSqmStatement() ) ) {
			hqlInterpretation.validateResultType( resultType );
			// NOTE: this copy is to isolate the actual AST tree from the
			// one stored in the interpretation cache
			return (SqmSelectStatement<T>)
					hqlInterpretation.getSqmStatement()
							.copy( noParamCopyContext( SqmQuerySource.CRITERIA ) );
		}
		else {
			throw new IllegalSelectQueryException( "Expecting a selection query, but found '" + hql + "'", hql );
		}
	}

	/**
	 * Used during construction to resolve an incoming named query reference
	 * and produce the corresponding SQM tree.
	 */
	@Nonnull
	private static <T> SqmSelectStatement<T> resolveSqmTree(
			@Nonnull NamedSqmQueryMemento<?> sqmMemento,
			@Nonnull Class<T> resultType,
			@Nonnull QueryEngine queryEngine) {
		final var sqmStatement = sqmMemento.getSqmStatement();
		if ( sqmStatement == null ) {
			return resolveSqmTree( sqmMemento.getHqlString(), resultType, queryEngine );
		}
		else if ( SqmUtil.isSelect( sqmStatement ) ) {
			//noinspection unchecked

View on GitHub (pinned to fad1729dce)

Solutions

  1. A selection specification requires a selection query. Supply an HQL/criteria select statement.

When it happens

Trigger: A Specification is given a statement of the wrong kind: Expecting a selection query, but found '<value>'

Common situations: Passing a select statement to MutationSpecification or a mutation statement to SelectionSpecification.


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