hibernate/hibernate-orm · error · IllegalQueryOperationException
Select item was not an entity type
Error message
Select item was not an entity type
What it means
Error "Select item was not an entity type" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/internal/KeyBasedPagination.java:66
}
yield sqmRoots.get( 0 );
}
case 1 -> items.get( 0 );
default -> throw new IllegalQueryOperationException("Query has multiple items in the select list");
};
if ( selected instanceof SqmFrom<?, ?> root ) {
statement.orderBy( keyDefinition.stream().map( order -> sortSpecification( statement, order ) )
.collect( toList() ) );
statement.select( keySelection( keyDefinition, root, selected, builder ) );
if ( keyValues != null ) {
final SqmPredicate restriction = keyRestriction( keyDefinition, keyValues, root, builder );
final SqmPredicate queryWhere = querySpec.getRestriction();
statement.where( queryWhere == null ? restriction : builder.and( queryWhere, restriction ) );
}
return statement;
}
else {
throw new IllegalQueryOperationException("Select item was not an entity type");
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
private static <R> SqmPredicate keyRestriction(
List<Order<? super R>> keyDefinition,
List<Comparable<?>> keyValues,
SqmFrom<?, ?> root,
NodeBuilder builder) {
final List<SqmPath<?>> keyPaths = new ArrayList<>();
for ( Order<? super R> key : keyDefinition ) {
keyPaths.add( root.get( key.attributeName() ) );
}
SqmPredicate restriction = null;
for (int i = 0; i < keyDefinition.size(); i++ ) {
// ordering by an attribute of the returned entity
final SortDirection direction = keyDefinition.get(i).direction();
final SqmPath key = keyPaths.get(i);View on GitHub (pinned to fad1729dce)
Solutions
- The select item of a key-paginated query must be an entity. Select the entity itself rather than scalar attributes.
When it happens
Trigger: A name/path expected to denote an entity type does not: Select item was not an entity type
Common situations: Passing non-entity arguments to version()/naturalid(), or a TREAT target / entity name that is not a mapped entity; commonly a typo or unmapped class.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b449a7913979ec27.
Report an issue: GitHub.