hibernate/hibernate-orm · error · SemanticException
Query has no 'select' clause, and multiple root entities, bu
Error message
Query has no 'select' clause, and multiple root entities, but query result type is an entity class (specify an explicit 'select' list, or a different result type, for example, 'Object[].class')
What it means
Error "Query has no 'select' clause, and multiple root entities, but query result type is an entity class (specify an explicit 'select' list, or a different result type, for example, 'Object[].class')" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1340
selectClause.addSelection( new SqmSelection<>( sqmRoot, sqmRoot.getAlias(), nodeBuilder) );
return selectClause;
}
else {
// there's more than one entity, and no entity is 'this',
// therefore the 'select' list cannot be inferred
throw new SemanticException( "Query has no 'select' clause, and multiple root entities, but no result type was given"
+ " (pass an explicit result type to 'createQuery()')", query );
}
}
}
else {
// we have an explicit result type, so we can use that to
// help infer the 'select' list
if ( creationContext.getJpaMetamodel().findEntityType( expectedResultType ) != null ) {
// the result type is an entity class
if ( fromClause.getNumberOfRoots() > 1 ) {
// multiple root entities
throw new SemanticException( "Query has no 'select' clause, and multiple root entities, but query result type is an entity class"
+ " (specify an explicit 'select' list, or a different result type, for example, 'Object[].class')",
query );
}
else {
final var sqmRoot = fromClause.getRoots().get(0);
if ( sqmRoot instanceof SqmCteRoot ) {
throw new SemanticException( "Query has no 'select' clause, and the 'from' clause refers to a CTE, but query result type is an entity class"
+ " (specify an explicit 'select' list)",
query );
}
else {
// exactly one root entity, return it
// (joined entities are not returned)
final var selectClause =
new SqmSelectClause( false, 1, nodeBuilder );
selectClause.addSelection( new SqmSelection<>( sqmRoot, sqmRoot.getAlias(), nodeBuilder) );
return selectClause;
}View on GitHub (pinned to fad1729dce)
Solutions
- Add an explicit 'select' list, or change the result type (e.g. Object[].class).
- Reduce the query to a single root entity.
When it happens
Trigger: The HQL/JPQL query violates a structural language rule.
Common situations: Writing queries with missing select/from, mismatched group by positions, or invalid ordering constructs.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/5da0306c6a1b9b36.
Report an issue: GitHub.