hibernate/hibernate-orm · error · SemanticException
Query has no 'select' clause, and multiple root entities…
Error message
Query has no 'select' clause, and multiple root entities, but no result type was given (pass an explicit result type to 'createQuery()')
What it means
Thrown while inferring an implicit select list: the query has no 'select' clause, its 'from' clause declares multiple root entities, and no result type was given to createQuery(). With multiple roots Hibernate cannot decide what to return, so the caller must pass an explicit result type or write a 'select' clause.
Solutions
- Pass Object[].class (or another explicit result type) to createQuery.
- Add an explicit 'select' list choosing the needed roots.
Defensive patterns
Strategy: validation
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/2ea6a314c07a0264.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1328
// the alias 'this', so the 'select' list cannot be
// inferred
throw new SemanticException( "Query has no 'select' clause, and joins, but no result type was given"
+ " (pass an explicit result type to 'createQuery()')", query );
}
// exactly one root entity, and no joins - this includes
// the case where JPA says the entity has an implicit alias
// 'this', and that we should infer 'select this', but we
// accept even the case where the entity has an explicit
// alias, and infer 'select explicit_alias'
final var selectClause =
new SqmSelectClause( false, 1, nodeBuilder );
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 ) {View on GitHub (pinned to fad1729dce)