{"record":{"id":"a82012c573cd37d0","repo":"hibernate/hibernate-orm","slug":"anonymoustupleembeddablevaluedmodelpart-is-not-fet","errorCode":null,"errorMessage":"AnonymousTupleEmbeddableValuedModelPart is not fetchable","messagePattern":"AnonymousTupleEmbeddableValuedModelPart is not fetchable","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleEmbeddableValuedModelPart.java","lineNumber":408,"sourceCode":"\t@Override\n\tpublic int getFetchableKey() {\n\t\treturn fetchableIndex;\n\t}\n\n\t@Override\n\tpublic FetchOptions getMappedFetchOptions() {\n\t\treturn FETCH_OPTIONS;\n\t}\n\n\t@Override\n\tpublic Fetch generateFetch(\n\t\t\tFetchParent fetchParent,\n\t\t\tNavigablePath fetchablePath,\n\t\t\tFetchTiming fetchTiming,\n\t\t\tboolean selected,\n\t\t\tString resultVariable,\n\t\t\tDomainResultCreationState creationState) {\n\t\tthrow new UnsupportedOperationException( \"AnonymousTupleEmbeddableValuedModelPart is not fetchable\" );\n\t}\n\n\t@Override\n\tpublic int getNumberOfFetchables() {\n\t\treturn modelParts.length;\n\t}\n\n\t@Override\n\tpublic NavigableRole getNavigableRole() {\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic EntityMappingType findContainingEntityMapping() {\n\t\treturn null;\n\t}\n\n\t@Override","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleEmbeddableValuedModelPart.java#L390-L426","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the fetch: select the tuple's component attributes explicitly instead of fetching through the synthetic part","If fetch semantics are required, map the data as a real @Entity (e.g., a CTE typed by an actual entity) and fetch that","Guard generic fetch-creation code with an instanceof check on the model part before calling generateFetch-equivalent paths"],"exampleFix":"// before\nJpaCteCriteria<AddressDto> cte = query.with(\"addrs\", ...);\nRoot<Order> o = query.from(Order.class);\no.fetch(\"address\"); // reaches anonymous tuple embeddable -> UnsupportedOperationException\n\n// after — select the tuple components directly\nquery.multiselect(o.get(\"id\"), o.get(\"address\").get(\"city\"));","handlingStrategy":"type-guard","validationCode":"if (path.getReferencedPathSource() instanceof AnonymousTupleSqmPathSource) { /* do not fetch; select components explicitly */ } else { query.fetch(path); }","typeGuard":"static boolean isFetchablePath(Path<?> p) { return !(p.getReferencedPathSource() instanceof AnonymousTupleSqmPathSource); }","tryCatchPattern":"try { root.fetch(attr); } catch (UnsupportedOperationException e) { if (e.getMessage().contains(\"not fetchable\")) { /* fall back to selecting component attributes */ } else throw e; }","preventionTips":["Never apply fetch joins or entity graphs to CTE/dynamic-instantiation results","Select tuple components explicitly instead of fetching through synthetic parts","If fetch semantics are needed, map the projection as a real entity"],"tags":["hibernate","fetch","dynamic-instantiation","tuple","cte","embeddable"],"backgroundTag":"anonymous-tuple-not-fetchable","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}