hibernate/hibernate-orm · error · SemanticException
The SqmFrom node [{}] can not be used in a context where the
Error message
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. What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java:4773
}
else {
throw new SemanticException(
"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`"
);
}
}
else if ( actualModelPart instanceof DiscriminatedAssociationModelPart discriminatedAssociationModelPart ) {
result = DiscriminatedAssociationPathInterpretation.from(
navigablePath,
discriminatedAssociationModelPart,
tableGroup,
this
);
}
else {
throw new SemanticException(
"The SqmFrom node [" + path + "] can not be used in a context where the expression needs to " +
"be expanded to identifying parts, because the model part [" + actualModelPart +
"] does not have identifying parts."
);
}
}
return withTreatRestriction( result, path );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SqmPath
@Override
public Expression visitBasicValuedPath(SqmBasicValuedSimplePath<?> sqmPath) {
final var path = prepareReusablePath(
sqmPath,
() -> BasicValuedPathInterpretation.from(View on GitHub (pinned to fad1729dce)
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
Example fix
// before select o from Ord o where o.anyRef = :ref // after select o from Ord o where o.anyRef.id = :refId
Defensive patterns
Strategy: try-catch
Validate before calling
// For @Any or non-identifiable paths: forbid whole-object comparisons in generated filters
if (generatedPredicateComparesWholePath) { // your query-builder knows which paths are @Any/embeddable
throw new IllegalArgumentException("Compare the identifier/sub-attribute, not the whole path");
} Try / catch
try {
return session.createQuery(hql).getResultList();
} catch (org.hibernate.query.SemanticException e) {
log.error("Path without identifying parts rejected: {}", hql, e);
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Insert conflict 'do update' clause with constraint name is n
- Summarization is not supported by DBMS
- Insert conflict 'do update' clause with constraint name is n
- Insert conflict 'do update' clause with constraint name is n
- Insert conflict 'do update' clause with constraint name is n
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/cfd8b045ad23f217.
Report an issue: GitHub.