hibernate/hibernate-orm · error · InterpretationException
Access to from node '" + from.getCorrelationParent() + "' is
Error message
Access to from node '" + from.getCorrelationParent() + "' is not possible in from-clause subqueries, unless the 'lateral' keyword is used for the subquery!
What it means
Thrown while translating a from-clause subquery (derived table). The subquery references the correlation parent of one of its SqmFrom nodes, but fromClauseIndex.findTableGroup() cannot find a table group for that parent's navigable path. Standard SQL forbids a derived table from seeing outer-query aliases unless the join is declared LATERAL, so Hibernate refuses to translate it.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java:2921
// If we have just inner joins against a correlated root, we can render the joins as references
// If we correlate a join, we have to create a special SqmRoot shell called SqmCorrelatedRootJoin.
// The only purpose of that is to serve as SqmRoot, which is needed for the FROM clause.
// It will always contain just a single correlated join though, which is what is actually correlated
final SqmFrom<?, ?> from;
if ( sqmRoot instanceof SqmCorrelatedRootJoin<?> ) {
final var sqmJoins = sqmRoot.getSqmJoins();
assert sqmJoins.size() == 1
&& sqmJoins.get( 0 ).isCorrelated();
from = sqmJoins.get( 0 );
}
else {
from = sqmRoot;
}
final var parentTableGroup = fromClauseIndex.findTableGroup(
from.getCorrelationParent().getNavigablePath()
);
if ( parentTableGroup == null ) {
throw new InterpretationException( "Access to from node '" + from.getCorrelationParent() + "' is not possible in from-clause subqueries, unless the 'lateral' keyword is used for the subquery!" );
}
final var sqlAliasBase = sqlAliasBaseManager.createSqlAliasBase( parentTableGroup.getGroupAlias() );
if ( parentTableGroup instanceof PluralTableGroup pluralTableGroup ) {
final var correlatedPluralTableGroup = new CorrelatedPluralTableGroup(
parentTableGroup,
sqlAliasBase,
currentQuerySpec,
predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
sessionFactory
);
final var elementTableGroup = pluralTableGroup.getElementTableGroup();
if ( elementTableGroup != null ) {
final var correlatedElementTableGroup = new CorrelatedTableGroup(
elementTableGroup,
sqlAliasBase,
currentQuerySpec,
predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
sessionFactoryView on GitHub (pinned to fad1729dce)
Solutions
- Mark the derived join as lateral: 'left join lateral (select ...) alias on ...' so the subquery may reference outer aliases
- Move the correlation predicate out of the subquery (uncorrelate it) and correlate via the outer where-clause instead
- Replace the from-clause subquery with a scalar subquery in the select or where clause, which may correlate freely
- Fall back to a native SQL query if the dialect lacks lateral support
Example fix
// before
select p.id, c.total
from Person p,
(select sum(o.amount) as total from Ord o where o.personId = p.id) c
// after
select p.id, c.total
from Person p
left join lateral (select sum(o.amount) as total from Ord o where o.personId = p.id) c Defensive patterns
Strategy: validation
Validate before calling
// Reject derived tables that reference an outer alias without 'lateral' before running
boolean derivedReferencesOuter = hql.matches("(?is).*\\bjoin\\s*\\((.*?)\\).*")
&& referencesOuterAlias(hql); // custom check: alias from outer from-clause appears inside the (...) block
if (derivedReferencesOuter && !hql.toLowerCase().contains("lateral")) {
throw new IllegalArgumentException("Derived subquery correlates to outer alias; use 'join lateral' or a native query");
} Try / catch
try {
return session.createQuery(hql).getResultList();
} catch (org.hibernate.query.sqm.InterpretationException e) {
if (e.getMessage() != null && e.getMessage().contains("lateral")) {
return runNativeFallback(hql); // pre-approved native variant of the same query
}
throw e;
} Prevention
- Write correlated from-clause subqueries as 'left join lateral (...)' from the start
- Prefer correlated scalar subqueries in select/where over derived tables when porting SQL
- Add HQL smoke tests for every ported native query so this fails in CI, not production
When it happens
Trigger: HQL like 'select ... from A a join (select ... from B b where b.aId = a.id) d' - the derived table body references outer alias 'a' without the lateral keyword; criteria code using SqmSubQuery in the from clause with a correlation to the outer query but without marking the derived join lateral.
Common situations: Porting native SQL or JPQL queries that used correlated derived tables; Hibernate 6+ where HQL gained full subquery support and users try correlated from-clause subqueries for the first time; upgrading applications that previously fell back to native SQL.
Related errors
- FROM_SUBQUERY
- Insert conflict 'do update' clause with constraint name is n
- field type not supported on Derby: " + unit
- format() function not supported on Derby
- field type not supported on Derby: " + unit
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/4f8e20c20000504d.
Report an issue: GitHub.