{"record":{"id":"cfd8b045ad23f217","repo":"hibernate/hibernate-orm","slug":"the-sqmfrom-node-can-not-be-used-in-a-context","errorCode":null,"errorMessage":"The SqmFrom node [{}] can not be used in a context where the expression needs to be expanded to identifying parts, because the model part [{}] does not have identifying parts.","messagePattern":"The SqmFrom node \\[(.+?)\\] can not be used in a context where the expression needs to be expanded to identifying parts, because the model part \\[(.+?)\\] does not have identifying parts\\.","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java","lineNumber":4773,"sourceCode":"\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 +\n\t\t\t\t\t\t\t\t\"] does not have identifying parts.\"\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn withTreatRestriction( result, path );\n\t}\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// SqmPath\n\n\t@Override\n\tpublic Expression visitBasicValuedPath(SqmBasicValuedSimplePath<?> sqmPath) {\n\t\tfinal var path = prepareReusablePath(\n\t\t\t\tsqmPath,\n\t\t\t\t() -> BasicValuedPathInterpretation.from(","sourceCodeStart":4755,"sourceCodeEnd":4791,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java#L4755-L4791","documentation":"The generic sibling of the derived-root error: the SqmPath resolves to a model part that has no identifying parts (it is not an entity or embeddable mapping with identifiers), yet the surrounding context needs the expression expanded to identifying parts. Since every specialized branch (entity id, discrimininated association, tuple with ELEMENT) was skipped, the SemanticException reports both the path and the model part class.","triggerScenarios":"Comparing a whole non-identifiable path in '=' or 'in' predicates (e.g. a basic-typed root, an any-type association path, or a plural-attribute element without identifiers); using such a path where id expansion is required (treat-restricted comparisons, key()/id() style positions).","commonSituations":"Comparing an @Any association path or a component-typed path as a whole object; queries written against entities whose identity was removed during mapping refactor; projections over collection elements compared to literals.","solutions":["Compare the identifier or component attribute explicitly: 'where e.anyAssoc.id = :x' or 'where e.comp.value = :v'","Select the concrete sub-path you need instead of the parent path","If the path should be identifiable, fix the mapping so the model part actually exposes identifying parts"],"exampleFix":"// before\nselect o from Ord o where o.anyRef = :ref\n\n// after\nselect o from Ord o where o.anyRef.id = :refId","handlingStrategy":"try-catch","validationCode":"// For @Any or non-identifiable paths: forbid whole-object comparisons in generated filters\nif (generatedPredicateComparesWholePath) { // your query-builder knows which paths are @Any/embeddable\n    throw new IllegalArgumentException(\"Compare the identifier/sub-attribute, not the whole path\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(hql).getResultList();\n} catch (org.hibernate.query.SemanticException e) {\n    log.error(\"Path without identifying parts rejected: {}\", hql, e);\n    throw e;\n}","preventionTips":["Compare @Any associations via their id property (o.anyRef.id)","Compare embeddables field by field, never as whole objects","Document non-identifiable paths in your metamodel wrappers so query builders avoid whole-path comparisons"],"tags":["hibernate","hql","sqmpath","model-part","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"}