hibernate/hibernate-orm · error · QueryException
Query did not define any roots
Error message
Query did not define any roots
What it means
Error "Query did not define any roots" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java:406
throw new IllegalSelectQueryException(
"SelectionSpecification only supports HQL or criteria query references: "
+ typedQueryReference.getName()
);
}
}
/**
* Used during construction. Mainly used to group extracting and
* validating the root.
*/
@Nonnull
private SqmRoot<? extends T> extractRoot(
@Nonnull SqmSelectStatement<T> sqmStatement,
@Nonnull Class<T> resultType,
@Nonnull String hql) {
final var sqmRoots = sqmStatement.getQuerySpec().getRoots();
if ( sqmRoots.isEmpty() ) {
throw new QueryException( "Query did not define any roots", hql );
}
if ( sqmRoots.size() > 1 ) {
throw new QueryException( "Query defined multiple roots", hql );
}
final var sqmRoot = sqmRoots.iterator().next();
return validateRoot( sqmRoot, resultType, hql );
// for later, to support select lists
//validateResultType( sqmStatement, sqmRoot, resultType, hql );
}
@Nonnull
private SqmRoot<? extends T> validateRoot(
@Nonnull SqmRoot<?> sqmRoot,
@Nonnull Class<T> resultType,
@Nonnull String hql) {
final var javaType = sqmRoot.getJavaType();
if ( javaType != nullView on GitHub (pinned to fad1729dce)
Solutions
- The query defined no roots. Add a from-clause root entity.
When it happens
Trigger: The query structure does not meet the single-root/single-select-item requirement: Query did not define any roots
Common situations: Key-based pagination or Specifications applied to queries with zero/multiple roots or multi-item select lists.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/27b028ea50c3a3d5.
Report an issue: GitHub.