hibernate/hibernate-orm · error · SemanticException
query has no 'select' clause, and no root entities (every se
Error message
query has no 'select' clause, and no root entities (every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type)
What it means
Error "query has no 'select' clause, and no root entities (every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type)" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1274
//noinspection unchecked
return (EntityDomainType<R>) entityDescriptor;
}
else if ( expectedResultType != null ) {
final var entityDescriptor = jpaMetamodel.findEntityType( expectedResultType );
if ( entityDescriptor == null ) {
throw new SemanticException( "Query has no 'from' clause, and the result type '"
+ expectedResultTypeShortName + "' is not an entity type", query );
}
return entityDescriptor;
}
else {
return null;
}
}
protected SqmSelectClause buildInferredSelectClause(SqmFromClause fromClause) {
if ( fromClause.getNumberOfRoots() == 0 ) {
throw new SemanticException( "query has no 'select' clause, and no root entities"
+ " (every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type)",
query );
}
final var nodeBuilder = nodeBuilder();
for ( var sqmRoot : fromClause.getRoots() ) {
if ( "this".equals( sqmRoot.getExplicitAlias() ) ) {
// we found an entity with the alias 'this'
// assigned explicitly, JPA says we should
// infer the select list 'select this'
final var selectClause =
new SqmSelectClause( false, 1, nodeBuilder );
selectClause.addSelection( new SqmSelection<>( sqmRoot, "this", nodeBuilder) );
return selectClause;
}
}
if ( expectedResultType == null ) {View on GitHub (pinned to fad1729dce)
Solutions
- Add an explicit 'select' or 'from' clause, or pass an entity result type to createQuery.
- Rewrite the query with a clear 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/aff9a1e8b86b5fa8.
Report an issue: GitHub.