{"record":{"id":"91c744e1d5230829","repo":"hibernate/hibernate-orm","slug":"not-correlated","errorCode":null,"errorMessage":"Not correlated","messagePattern":"Not correlated","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/AbstractSqmFrom.java","lineNumber":327,"sourceCode":"\t\t}\n\t\ttreats.add( treat );\n\t\treturn treat;\n\t}\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// JPA\n\n\n\t@Nullable\n\t@Override\n\tpublic JpaPath<?> getParentPath() {\n\t\treturn getLhs();\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SqmFrom<O,T> getCorrelationParent() {\n\t\tthrow new IllegalStateException( \"Not correlated\" );\n\t}\n\n\t@Nonnull\n\tpublic abstract SqmCorrelation<O, T> createCorrelation();\n\n\t@Override\n\tpublic boolean isCorrelated() {\n\t\treturn false;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic Set<Join<T, ?>> getJoins() {\n\t\treturn getSqmJoins().stream()\n\t\t\t\t.filter( sqmJoin -> sqmJoin instanceof SqmAttributeJoin<?,?> attributeJoin\n\t\t\t\t\t\t&& !attributeJoin.isFetched() )\n\t\t\t\t.collect( Collectors.toSet() );\n\t}","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/AbstractSqmFrom.java#L309-L345","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSqmFrom<?, ?> parent = join.getCorrelationParent(); // throws for plain joins\n// after\nSqmFrom<?, ?> parent = join.isCorrelated() ? join.getCorrelationParent() : join.getLhs();","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static SqmFrom<?, ?> correlationParentOrLhs(SqmFrom<?, ?> from) {\n    return from.isCorrelated() ? from.getCorrelationParent() : from.getLhs();\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["hibernate","sqm","subquery","correlation","criteria-api"],"backgroundTag":"uncorrelated-subquery-access","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}