{"record":{"id":"f78c9c9ba87a2581","repo":"hibernate/hibernate-orm","slug":"the-derived-sqmfrom-anonymoustupletype-p","errorCode":null,"errorMessage":"The derived SqmFrom\" + ( (AnonymousTupleType<?>) path.getReferencedPathSource() ).getComponentNames() + \" can not be used in a context where the expression needs to be expanded to identifying parts, because a derived model part does not have identifying parts. Replace uses of the root with paths instead e.g. `derivedRoot.get(\\\"alias1\\\")` or `derivedRoot.alias1`","messagePattern":"The derived SqmFrom\" \\+ \\( \\(AnonymousTupleType<\\?>\\) path\\.getReferencedPathSource\\(\\) \\)\\.getComponentNames\\(\\) \\+ \" can not be used in a context where the expression needs to be expanded to identifying parts, because a derived model part does not have identifying parts\\. Replace uses of the root with paths instead e\\.g\\. `derivedRoot\\.get\\(\\\\\"alias1\\\\\"\\)` or `derivedRoot\\.alias1`","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java","lineNumber":4757,"sourceCode":"\t\t\t\t\tthrow new UnsupportedOperationException( \"Unsupported basic-valued path expression : \" + expression );\n\t\t\t\t}\n\t\t\t\tresult = new BasicValuedPathInterpretation<>(\n\t\t\t\t\t\tcolumnReference,\n\t\t\t\t\t\tnavigablePath,\n\t\t\t\t\t\tmapping,\n\t\t\t\t\t\ttableGroup\n\t\t\t\t);\n\t\t\t}\n\t\t\telse if ( actualModelPart instanceof AnonymousTupleTableGroupProducer tableGroupProducer ) {\n\t\t\t\tfinal var subPart = tableGroupProducer.findSubPart(\n\t\t\t\t\t\tCollectionPart.Nature.ELEMENT.getName(),\n\t\t\t\t\t\tnull\n\t\t\t\t);\n\t\t\t\tif ( subPart != null ) {\n\t\t\t\t\treturn createExpression( tableGroup, navigablePath, subPart, path );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\"The derived SqmFrom\" + ( (AnonymousTupleType<?>) path.getReferencedPathSource() ).getComponentNames() + \" can not be used in a context where the expression needs to \" +\n\t\t\t\t\t\t\t\t\t\"be expanded to identifying parts, because a derived model part does not have identifying parts. \" +\n\t\t\t\t\t\t\t\t\t\"Replace uses of the root with paths instead e.g. `derivedRoot.get(\\\"alias1\\\")` or `derivedRoot.alias1`\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( actualModelPart instanceof DiscriminatedAssociationModelPart discriminatedAssociationModelPart ) {\n\t\t\t\tresult = DiscriminatedAssociationPathInterpretation.from(\n\t\t\t\t\t\tnavigablePath,\n\t\t\t\t\t\tdiscriminatedAssociationModelPart,\n\t\t\t\t\t\ttableGroup,\n\t\t\t\t\t\tthis\n\t\t\t\t);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\"The SqmFrom node [\" + path + \"] can not be used in a context where the expression needs to \" +\n\t\t\t\t\t\t\t\t\"be expanded to identifying parts, because the model part [\" + actualModelPart +","sourceCodeStart":4739,"sourceCodeEnd":4775,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java#L4739-L4775","documentation":"A path whose referenced path source is an AnonymousTupleType (the result of a select-subquery used as a derived root, or a tuple-typed expression) was used in a position where Hibernate must expand the expression to its identifying parts. A derived model part has no identifying parts, and no ELEMENT sub-part was found on the AnonymousTupleTableGroupProducer, so the SemanticException tells you to address the components directly.","triggerScenarios":"HQL 'from (select ...) d where d = :p' or 'd in (...)' comparing the whole derived root; ordering or grouping by the bare derived root; using the derived root where an entity reference is expected (treat, id()...).","commonSituations":"Hibernate 6+ applications replacing native derived-table queries with HQL; criteria queries with JpaSubQuery in the from clause whose result is then compared as a whole; refactor of DTO projections that accidentally compares the tuple root instead of its aliases.","solutions":["Reference component aliases instead of the root: 'where d.alias1 = :p'","Select explicit components when the subquery builds the tuple so each has a stable alias","Restructure the comparison against the underlying entity path rather than the derived tuple"],"exampleFix":"// before\nselect d from (select p.id as pid, p.name as name from Person p) d where d = :p\n\n// after\nselect d from (select p.id as pid, p.name as name from Person p) d where d.pid = :pid","handlingStrategy":"validation","validationCode":"// For dynamic HQL over derived roots: whitelist only component-qualified references\n// e.g. allow 'd.alias' but reject bare 'd =' / 'd in'\nif (hql.matches(\"(?is)\\\\bd\\\\s*(=|in|<>)\\\\s*\")) {\n    throw new IllegalArgumentException(\"Derived root used as a whole; reference components like d.alias1\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(hql).getResultList();\n} catch (org.hibernate.query.SemanticException e) {\n    log.error(\"Derived tuple path rejected: {}\", hql, e);\n    throw e;\n}","preventionTips":["Always alias every component of a select-subquery used as a derived root","Reference components explicitly (d.pid) instead of the tuple root in predicates","Keep derived roots for projections only; correlate on real entity paths in predicates"],"tags":["hibernate","hql","derived-root","tuple-type","query-translation"],"backgroundTag":"sqm-path-identifying-parts","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}