hibernate/hibernate-orm · error · UnsupportedOperationException

Anonymous tuple path source does not have a declaring type

Error message

Anonymous tuple path source does not have a declaring type

What it means

AnonymousTupleSqmAssociationPathSource is the synthetic path source Hibernate creates for association attributes of tuple-typed results (CTE attributes, select-new/tuple selects used as associations). It does not correspond to a mapped attribute, so there is no managed type that declares it, and getDeclaringType() always throws UnsupportedOperationException. Real metamodel questions must be asked of the actual mapped entity types, not of tuple-derived path sources.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleSqmAssociationPathSourceNew.java:82

		return domainType.getJavaType();
	}

	@Override
	@Nonnull
	public Class<J> getJavaType() {
		return domainType.getJavaType();
	}

	@Override
	@Nonnull
	public SimpleDomainType<J> getType() {
		return domainType;
	}

	@Override
	@Nonnull
	public ManagedDomainType<O> getDeclaringType() {
		throw new UnsupportedOperationException( "Anonymous tuple path source does not have a declaring type" );
	}

	@Override
	public SqmPathSource<J> getSqmPathSource() {
		return this;
	}

	@Override
	public boolean isId() {
		return false;
	}

	@Override
	public boolean isVersion() {
		return false;
	}

	@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Skip introspection for synthetic sources: check 'attribute instanceof AnonymousTupleSqmPathSource' (package org.hibernate.query.sqm.tuple.internal) before calling getDeclaringType()
  2. Run metamodel analysis against the real mapped entity/managed types from jakarta.persistence.metamodel.Metamodel instead of tuple query paths
  3. Track declaring types yourself when building tuple-typed queries, since the tuple cannot supply them

Example fix

// before
for (Attribute<?, ?> a : managedType.getAttributes()) {
    ManagedDomainType<?> owner = ((SqmPathSource<?>) a).getDeclaringType(); // blows up on tuple sources
}

// after
if (a instanceof AnonymousTupleSqmPathSource) {
    continue; // synthetic tuple attribute: no declaring type
}
ManagedDomainType<?> owner = ((SqmPathSource<?>) a).getDeclaringType();
Defensive patterns

Strategy: type-guard

Validate before calling

if (source instanceof AnonymousTupleSqmPathSource) { /* synthetic: no declaring type, skip */ } else { ManagedDomainType<?> dt = source.getDeclaringType(); }

Type guard

static boolean hasDeclaringType(SqmPathSource<?> s) { return !(s instanceof AnonymousTupleSqmPathSource); }

Try / catch

try { return source.getDeclaringType(); } catch (UnsupportedOperationException e) { if (e.getMessage().contains("declaring type")) return null; throw e; }

Prevention

When it happens

Trigger: Metamodel-style introspection that walks Attribute/PathSource and calls getDeclaringType() on a source that came from a CTE attribute or dynamic-instantiation path — e.g., auditing frameworks, DTO mappers, or validation code traversing attribute declarations.

Common situations: Generic metamodel walkers applied to Hibernate-specific tuple queries; code that renders criteria trees to strings/SQL and prints the declaring type; upgrades where previously plain paths became tuple path sources.

Related errors


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