{"record":{"id":"0a875a50f7e8b59a","repo":"hibernate/hibernate-orm","slug":"anonymoustupletype-cannot-be-used-to-create-an-sqm","errorCode":null,"errorMessage":"AnonymousTupleType cannot be used to create an SqmPath - that would be an SqmFrom which are created directly","messagePattern":"AnonymousTupleType cannot be used to create an SqmPath - that would be an SqmFrom which are created directly","errorType":"exception","errorClass":"UnsupportedMappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java","lineNumber":284,"sourceCode":"\n\t@Override\n\tpublic String getPathName() {\n\t\treturn \"tuple\" + System.identityHashCode( this );\n\t}\n\n\t@Override\n\tpublic SqmDomainType<T> getPathType() {\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic @Nullable SqmDomainType<T> getSqmType() {\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic SqmPath<T> createSqmPath(SqmPath<?> lhs, @Nullable SqmPathSource<?> intermediatePathSource) {\n\t\tthrow new UnsupportedMappingException(\n\t\t\t\t\"AnonymousTupleType cannot be used to create an SqmPath - that would be an SqmFrom which are created directly\"\n\t\t);\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Class<T> getBindableJavaType() {\n\t\treturn javaTypeDescriptor.getJavaTypeClass();\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Class<T> getJavaType() {\n\t\treturn javaTypeDescriptor.getJavaTypeClass();\n\t}\n\n\t@Override\n\tpublic String toString() {","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleType.java#L266-L302","documentation":"AnonymousTupleType implements SqmPathSource, but a path over an anonymous tuple would have to be an SqmFrom, and SQM creates SqmFrom elements directly for from-clause roots. createSqmPath therefore always throws UnsupportedMappingException - the tuple type is not a navigable you can join or path-create through.","triggerScenarios":"Query translation or programmatic SQM calls createSqmPath with the tuple type as the path source: treating the CTE/subquery tuple like a managed type by joining to it, fetching from it, using treat expressions, or building paths off it in custom criteria code.","commonSituations":"Writing HQL that treats a CTE root as an entity (join/fetch off `cteRoot.someAssociation`); criteria frameworks that call createSqmPath generically on every path source; upgrading applications that previously used native SQL for these shapes.","solutions":["Navigate only the tuple's component aliases (t.id, t.name); never join or fetch from the tuple root.","If you need association navigation, use a real mapped entity in the CTE/from clause instead of an anonymous tuple.","Rewrite joins over CTE results as IN/correlated subqueries against the component columns.","Upgrade Hibernate ORM - tuple handling improves across 6.x releases and may support your shape later."],"exampleFix":"// before - treating the tuple as a joinable managed type\n\"with c as (select e.id as id from Entity e) select o.total from c join c.order o\"\n// -> UnsupportedMappingException: AnonymousTupleType cannot be used to create an SqmPath\n\n// after - join real entities, use the tuple only for scalar filtering\n\"select o.total from Order o where o.id in (select c.id from c)\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(hql).getResultList();\n} catch (UnsupportedMappingException e) {\n    // tuple treated as navigable/joinable type; navigate component aliases only\n    throw new QueryDesignException(\"CTE tuple cannot be joined or path-navigated: \" + hql, e);\n}","preventionTips":["Never join, fetch or treat CTE tuple roots as managed types.","Use CTEs for scalar filtering (IN subqueries) and join real entities instead.","Map persistent row shapes as entities/embeddables when association navigation is needed."],"tags":["hibernate","sqm","mapping","cte","tuple"],"backgroundTag":"unsupported-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}