hibernate/hibernate-orm · error · IllegalStateException
The JPA specification does not support subqueries in select
Error message
The JPA specification does not support subqueries in select clauses. Please disable the JPA query compliance if you want to use this feature.
What it means
Error "The JPA specification does not support subqueries in select clauses. Please disable the JPA query compliance if you want to use this feature." thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmSelectStatement.java:399
"empty selections passed to criteria query typed as Object" );
case 1 -> (JpaSelection<?>) selections.get( 0 );
default -> nodeBuilder().array( selections );
};
}
else if ( Tuple.class.isAssignableFrom( resultType ) ) {
return nodeBuilder().tuple( selections );
}
else if ( resultType.isArray() ) {
return nodeBuilder().array( resultType, selections );
}
else {
return nodeBuilder().construct( resultType, selections );
}
}
private void checkSelectionIsJpaCompliant(Selection<?> selection) {
if ( selection instanceof SqmSubQuery<?> ) {
throw new IllegalStateException(
"The JPA specification does not support subqueries in select clauses. " +
"Please disable the JPA query compliance if you want to use this feature." );
}
}
@Nonnull
@Override
public SqmSelectStatement<T> orderBy(@Nonnull Order... orders) {
final SqmOrderByClause sqmOrderByClause = new SqmOrderByClause( orders.length );
for ( Order order : orders ) {
sqmOrderByClause.addSortSpecification( (SqmSortSpecification) order );
}
getQueryPart().setOrderByClause( sqmOrderByClause );
return this;
}
@Nonnull
@OverrideView on GitHub (pinned to fad1729dce)
Solutions
- Disable JPA query compliance to allow subqueries in the SELECT clause.
- Move the subquery into the WHERE clause or restructure the query to compute the value via a join.
- Use HQL or native SQL for this query, which do not enforce the JPA restriction.
When it happens
Trigger: A subquery is placed in the SELECT clause while JPA query compliance mode is enabled.
Common situations: Using scalar subqueries in the select list under strict JPA compliance; disable compliance or move the subquery to WHERE.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/09405b4727826460.
Report an issue: GitHub.