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

  1. Guard with isCorrelated() before calling getCorrelationParent().
  2. For subqueries, create correlations explicitly via Subquery#correlate(root/join) and read the parent from the returned correlation.
  3. 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

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


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/91c744e1d5230829. Report an issue: GitHub.