hibernate/hibernate-orm · error · IllegalStateException
Not correlated
Error message
Not correlated
What it means
The base AbstractSqmFrom implements getCorrelationParent() by throwing IllegalStateException("Not correlated") and isCorrelated() as false. Only correlation nodes (SqmCorrelation subclasses created by createCorrelation() / subquery correlation APIs) carry a correlation parent; calling getCorrelationParent() on an ordinary SqmRoot or attribute join is invalid.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/AbstractSqmFrom.java:327
}
treats.add( treat );
return treat;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JPA
@Nullable
@Override
public JpaPath<?> getParentPath() {
return getLhs();
}
@Nonnull
@Override
public SqmFrom<O,T> getCorrelationParent() {
throw new IllegalStateException( "Not correlated" );
}
@Nonnull
public abstract SqmCorrelation<O, T> createCorrelation();
@Override
public boolean isCorrelated() {
return false;
}
@Nonnull
@Override
public Set<Join<T, ?>> getJoins() {
return getSqmJoins().stream()
.filter( sqmJoin -> sqmJoin instanceof SqmAttributeJoin<?,?> attributeJoin
&& !attributeJoin.isFetched() )
.collect( Collectors.toSet() );
}View on GitHub (pinned to fad1729dce)
Solutions
- Guard with isCorrelated() before calling getCorrelationParent().
- For subqueries, create correlations explicitly via Subquery#correlate(root/join) and read the parent from the returned correlation.
- For navigation, use getLhs() / getReferencedPathSource() instead, which are valid on plain joins.
Example fix
// before SqmFrom<?, ?> parent = join.getCorrelationParent(); // throws for plain joins // after SqmFrom<?, ?> parent = join.isCorrelated() ? join.getCorrelationParent() : join.getLhs();
Defensive patterns
Strategy: type-guard
Type guard
static SqmFrom<?, ?> correlationParentOrLhs(SqmFrom<?, ?> from) {
return from.isCorrelated() ? from.getCorrelationParent() : from.getLhs();
} Prevention
- Always pair isCorrelated() with getCorrelationParent() in walkers/copiers.
- Create correlations via Subquery#correlate(...) and keep the returned correlation node.
- Use getLhs()/getReferencedPathSource() for plain navigation on non-correlated joins.
When it happens
Trigger: Custom SQM walkers/copiers/renderers that uniformly call from.getCorrelationParent() on every SqmFrom; calling getCorrelationParent() on a join before the owning subquery has correlated it.
Common situations: Framework or tooling code that inspects query trees (criteria-to-SQL renderers, audit/rewrite layers) and assumes every from-node is correlated; porting JPA subquery code where correlate() was expected to be implicit.
Related errors
- Correlated derived root does not have an entity type. Use ge
- Correlated derived root does not have an entity type. Use ge
- Can't set alias on a correlated root
- JPA selection is not compound
- Cannot correlate from node [${parentFrom}]
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/91c744e1d5230829.
Report an issue: GitHub.