hibernate/hibernate-orm · error · IllegalSelectQueryException

Not a HQL query

Error message

Not a HQL query

What it means

Error "Not a HQL query" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:589

//	private Class<R> extractResultClass(ResultSetMapping resultSetMapping) {
//		final List<ResultBuilder> resultBuilders = resultSetMapping.getResultBuilders();
//		if ( resultBuilders.size() == 1 ) {
//			final ResultBuilder resultBuilder = resultBuilders.get( 0 );
//			if ( resultBuilder instanceof ImplicitResultClassBuilder
//				|| resultBuilder instanceof ImplicitModelPartResultBuilderEntity
//				|| resultBuilder instanceof DynamicResultBuilderEntityCalculated ) {
//				//noinspection unchecked
//				return (Class<R>) resultBuilder.getJavaType();
//			}
//		}
//		return null;
//	}

	@Override
	@Nonnull
	public <X> SelectionQueryImplementor<X> asSelectionQuery(EntityGraph<X> graph, GraphSemantic semantic) {
		throw new IllegalSelectQueryException( "Not a HQL query", getQueryString() );
	}

	@Override
	@Nonnull
	public NativeQueryImplementor<R> asSelectionQuery() {
		errorIfNotSelectForSure();
		return this;
	}

	@Override
	@Nonnull
	public <X> NativeQueryImplementor<X> asSelectionQuery(Class<X> type) {
		errorIfNotSelectForSure();
		checkResultType( type, resultSetMapping() );
		//noinspection unchecked
		return (NativeQueryImplementor<X>) this;
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. This operation requires an HQL/JPQL query; you passed a native SQL query.
  2. Use createQuery(...) (HQL) instead of createNativeQuery(...), or use the native-query-specific API.

When it happens

Trigger: A query object is used through an interface or role it does not implement.

Common situations: Casting or unwrapping a native/HQL, select/mutation query to the wrong type, or passing a non-property path where one is required.


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