hibernate/hibernate-orm · error · SemanticException

The derived SqmFrom" + ( (AnonymousTupleType<?>) path.getRef

Error message

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`

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java:4757

					throw new UnsupportedOperationException( "Unsupported basic-valued path expression : " + expression );
				}
				result = new BasicValuedPathInterpretation<>(
						columnReference,
						navigablePath,
						mapping,
						tableGroup
				);
			}
			else if ( actualModelPart instanceof AnonymousTupleTableGroupProducer tableGroupProducer ) {
				final var subPart = tableGroupProducer.findSubPart(
						CollectionPart.Nature.ELEMENT.getName(),
						null
				);
				if ( subPart != null ) {
					return createExpression( tableGroup, navigablePath, subPart, path );
				}
				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 +

View on GitHub (pinned to fad1729dce)

Solutions

  1. Reference component aliases instead of the root: 'where d.alias1 = :p'
  2. Select explicit components when the subquery builds the tuple so each has a stable alias
  3. Restructure the comparison against the underlying entity path rather than the derived tuple

Example fix

// before
select d from (select p.id as pid, p.name as name from Person p) d where d = :p

// after
select d from (select p.id as pid, p.name as name from Person p) d where d.pid = :pid
Defensive patterns

Strategy: validation

Validate before calling

// For dynamic HQL over derived roots: whitelist only component-qualified references
// e.g. allow 'd.alias' but reject bare 'd =' / 'd in'
if (hql.matches("(?is)\\bd\\s*(=|in|<>)\\s*")) {
    throw new IllegalArgumentException("Derived root used as a whole; reference components like d.alias1");
}

Try / catch

try {
    return session.createQuery(hql).getResultList();
} catch (org.hibernate.query.SemanticException e) {
    log.error("Derived tuple path rejected: {}", hql, e);
    throw e;
}

Prevention

When it happens

Trigger: 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()...).

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/f78c9c9ba87a2581. Report an issue: GitHub.