{"record":{"id":"667445cc643eddc4","repo":"hibernate/hibernate-orm","slug":"anonymous-tuple-path-source-does-not-have-a-declar","errorCode":null,"errorMessage":"Anonymous tuple path source does not have a declaring type","messagePattern":"Anonymous tuple path source does not have a declaring type","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleSqmAssociationPathSourceNew.java","lineNumber":82,"sourceCode":"\t\treturn domainType.getJavaType();\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Class<J> getJavaType() {\n\t\treturn domainType.getJavaType();\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic SimpleDomainType<J> getType() {\n\t\treturn domainType;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic ManagedDomainType<O> getDeclaringType() {\n\t\tthrow new UnsupportedOperationException( \"Anonymous tuple path source does not have a declaring type\" );\n\t}\n\n\t@Override\n\tpublic SqmPathSource<J> getSqmPathSource() {\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic boolean isId() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean isVersion() {\n\t\treturn false;\n\t}\n\n\t@Override","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tuple/internal/AnonymousTupleSqmAssociationPathSourceNew.java#L64-L100","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Skip introspection for synthetic sources: check 'attribute instanceof AnonymousTupleSqmPathSource' (package org.hibernate.query.sqm.tuple.internal) before calling getDeclaringType()","Run metamodel analysis against the real mapped entity/managed types from jakarta.persistence.metamodel.Metamodel instead of tuple query paths","Track declaring types yourself when building tuple-typed queries, since the tuple cannot supply them"],"exampleFix":"// before\nfor (Attribute<?, ?> a : managedType.getAttributes()) {\n    ManagedDomainType<?> owner = ((SqmPathSource<?>) a).getDeclaringType(); // blows up on tuple sources\n}\n\n// after\nif (a instanceof AnonymousTupleSqmPathSource) {\n    continue; // synthetic tuple attribute: no declaring type\n}\nManagedDomainType<?> owner = ((SqmPathSource<?>) a).getDeclaringType();","handlingStrategy":"type-guard","validationCode":"if (source instanceof AnonymousTupleSqmPathSource) { /* synthetic: no declaring type, skip */ } else { ManagedDomainType<?> dt = source.getDeclaringType(); }","typeGuard":"static boolean hasDeclaringType(SqmPathSource<?> s) { return !(s instanceof AnonymousTupleSqmPathSource); }","tryCatchPattern":"try { return source.getDeclaringType(); } catch (UnsupportedOperationException e) { if (e.getMessage().contains(\"declaring type\")) return null; throw e; }","preventionTips":["Branch on instanceof AnonymousTupleSqmPathSource in every metamodel walker that touches Hibernate SQM paths","Run metamodel analysis on EntityManagerFactory.getMetamodel() types, never on tuple query paths","Encapsulate attribute introspection behind one audited helper"],"tags":["hibernate","metamodel","tuple","path-source","cte"],"backgroundTag":"anonymous-tuple-metamodel-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}