hibernate/hibernate-orm · error · IllegalQueryOperationException
Result type given for a non-SELECT Query
Error message
Result type given for a non-SELECT Query
What it means
Error "Result type given for a non-SELECT Query" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/internal/SelectionQueryImpl.java:1198
);
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Utilities
private static <R> void validateQuery(Class<R> expectedResultType, SqmStatement<R> sqm, String hql) {
if ( sqm instanceof SqmSelectStatement<R> selectStatement ) {
final var queryPart = selectStatement.getQueryPart();
// For criteria queries, we have to validate the fetch structure here
queryPart.validateQueryStructureAndFetchOwners();
validateCriteriaQuery( queryPart );
selectStatement.validateResultType( expectedResultType );
}
else if ( sqm instanceof AbstractSqmDmlStatement<R> update ) {
if ( expectedResultType != null ) {
throw new IllegalQueryOperationException( "Result type given for a non-SELECT Query", hql, null );
}
update.validate( hql );
}
}
private SelectQueryPlan<R> resolveQueryPlan() {
final var queryCache = getInterpretationCache();
if ( queryCache.isEnabled() ) {
final var cacheKey = createInterpretationsKey( this );
return cacheKey == null
? buildSelectQueryPlan()
: queryCache.resolveSelectQueryPlan( cacheKey, this::buildSelectQueryPlan );
}
else {
return buildSelectQueryPlan();
}
}View on GitHub (pinned to fad1729dce)
Solutions
- A result type was specified for a non-SELECT query. Remove the result type, or use a select query.
When it happens
Trigger: The requested result type does not match what the query produces: Result type given for a non-SELECT Query
Common situations: Creating a typed query whose result class differs from the query root/select item type, or passing a result type for a non-select statement.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/318b4320d193816f.
Report an issue: GitHub.