hibernate/hibernate-orm · error · UnsupportedOperationException

AnonymousTupleEmbeddableValuedModelPart is not fetchable

Error message

AnonymousTupleEmbeddableValuedModelPart is not fetchable

What it means

Anonymous tuple model parts are synthetic: they exist to map the values produced by a dynamic instantiation, CTE, or tuple select, and carry no association metadata for the runtime join machinery. Consequently generateFetch() on AnonymousTupleEmbeddableValuedModelPart always throws UnsupportedOperationException — you cannot join-fetch through such a part.

Source

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

	@Override
	public int getFetchableKey() {
		return fetchableIndex;
	}

	@Override
	public FetchOptions getMappedFetchOptions() {
		return FETCH_OPTIONS;
	}

	@Override
	public Fetch generateFetch(
			FetchParent fetchParent,
			NavigablePath fetchablePath,
			FetchTiming fetchTiming,
			boolean selected,
			String resultVariable,
			DomainResultCreationState creationState) {
		throw new UnsupportedOperationException( "AnonymousTupleEmbeddableValuedModelPart is not fetchable" );
	}

	@Override
	public int getNumberOfFetchables() {
		return modelParts.length;
	}

	@Override
	public NavigableRole getNavigableRole() {
		return null;
	}

	@Override
	public EntityMappingType findContainingEntityMapping() {
		return null;
	}

	@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove the fetch: select the tuple's component attributes explicitly instead of fetching through the synthetic part
  2. If fetch semantics are required, map the data as a real @Entity (e.g., a CTE typed by an actual entity) and fetch that
  3. Guard generic fetch-creation code with an instanceof check on the model part before calling generateFetch-equivalent paths

Example fix

// before
JpaCteCriteria<AddressDto> cte = query.with("addrs", ...);
Root<Order> o = query.from(Order.class);
o.fetch("address"); // reaches anonymous tuple embeddable -> UnsupportedOperationException

// after — select the tuple components directly
query.multiselect(o.get("id"), o.get("address").get("city"));
Defensive patterns

Strategy: type-guard

Validate before calling

if (path.getReferencedPathSource() instanceof AnonymousTupleSqmPathSource) { /* do not fetch; select components explicitly */ } else { query.fetch(path); }

Type guard

static boolean isFetchablePath(Path<?> p) { return !(p.getReferencedPathSource() instanceof AnonymousTupleSqmPathSource); }

Try / catch

try { root.fetch(attr); } catch (UnsupportedOperationException e) { if (e.getMessage().contains("not fetchable")) { /* fall back to selecting component attributes */ } else throw e; }

Prevention

When it happens

Trigger: Calling fetch() (or having Hibernate create a fetch) on a path whose model part is an anonymous tuple embeddable — e.g., fetch-joining a CTE attribute or an embeddable-shaped select-new result, or applying an EntityGraph/fetch profile that reaches a tuple-typed attribute.

Common situations: Treating CTE or dynamic-instantiation results like mapped entities and applying normal fetch strategies; fetch graphs defined on query results that were later switched to tuple projections.

Related errors


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