hibernate/hibernate-orm · error · IllegalStateException
The JPA specification does not support subqueries in the fro
Error message
The JPA specification does not support subqueries in the from clause. Please disable the JPA query compliance if you want to use this feature.
What it means
AbstractSqmFrom.validateComplianceFromSubQuery runs before Hibernate-specific FROM-clause joins of subqueries (derived tables / lateral joins, e.g. root.join(subQuery)); when JPA query compliance (hibernate.jpa.compliance.query) is enabled it throws IllegalStateException because the JPA specification only allows subqueries in WHERE/HAVING. The same validator guards the CTE/subquery join entry points on JpaFrom.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/AbstractSqmFrom.java:827
}
@Nonnull
@Override
public <X> JpaFunctionJoin<X> joinArrayCollection(@Nonnull SingularAttribute<? super T, ? extends Collection<X>> collectionAttribute) {
return joinArrayCollection( collectionAttribute, SqmJoinType.INNER );
}
@Nonnull
@Override
public <X> JpaFunctionJoin<X> joinArrayCollection(
@Nonnull SingularAttribute<? super T, ? extends Collection<X>> collectionAttribute,
@Nonnull SqmJoinType joinType) {
return join( nodeBuilder().unnestCollection( get( collectionAttribute ) ), joinType, true );
}
private void validateComplianceFromSubQuery() {
if ( nodeBuilder().isJpaQueryComplianceEnabled() ) {
throw new IllegalStateException(
"The JPA specification does not support subqueries in the from clause. "
+ "Please disable the JPA query compliance if you want to use this feature." );
}
}
private void validateComplianceFromFunction() {
if ( nodeBuilder().isJpaQueryComplianceEnabled() ) {
throw new IllegalStateException(
"The JPA specification does not support functions in the from clause. "
+ "Please disable the JPA query compliance if you want to use this feature." );
}
}
@Nonnull
@Override
public <X> JpaCrossJoin<T, X> crossJoin(@Nonnull Class<X> entityJavaType) {
return crossJoin( nodeBuilder().getDomainModel().entity( entityJavaType ) );
}View on GitHub (pinned to fad1729dce)
Solutions
- Disable the setting: hibernate.jpa.compliance.query=false (xml property jakarta.persistence... or hibernate.jpa.compliance.query in persistence.xml/SessionFactory config).
- Restructure the query to use a correlated subquery in the WHERE clause instead of a FROM join.
- If the flag must stay on, move the Hibernate-specific query to HQL or a separate, non-compliant SessionFactory.
Example fix
// before (hibernate.jpa.compliance.query=true) root.join( idsSubQuery ); // subquery join in FROM -> IllegalStateException // after // persistence.xml: <property name="hibernate.jpa.compliance.query" value="false"/> // or restructure with a WHERE-clause subquery: query.where( cb.exists( idsSubQuery ) );
Defensive patterns
Strategy: validation
Validate before calling
if ( cb.isJpaQueryComplianceEnabled() ) {
// restructure: correlated subquery in WHERE instead of a FROM join
query.where( cb.exists( subquery ) );
} else {
root.join( subQuery );
} Type guard
static boolean fromSubqueryJoinAllowed(HibernateCriteriaBuilder cb) {
return !cb.isJpaQueryComplianceEnabled();
} Prevention
- Know whether hibernate.jpa.compliance.query is enabled in every persistence unit your query code touches.
- Keep Hibernate-specific FROM-join queries in code paths only used with compliance disabled.
- Prefer WHERE-clause subqueries for portable criteria code.
When it happens
Trigger: root.join(subQuery) (join(JpaSubQuery, SqmJoinType, ...) path) while hibernate.jpa.compliance.query=true; using derived-table or lateral joins in the FROM clause of a criteria query in a compliant persistence unit.
Common situations: Turning on JPA compliance for portability/certification and having existing criteria queries that join subqueries in FROM; sharing query code between a compliant and a non-compliant persistence unit, so it only fails in one environment.
Related errors
- The JPA specification does not support functions in the from
- The JPA specification does not support subqueries having mul
- UNMAPPED_POLYMORPHISM
- FROM_SUBQUERY
- FROM_FUNCTION
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/9a871991861f268b.
Report an issue: GitHub.