{"record":{"id":"739db5ef009168e3","repo":"hibernate/hibernate-orm","slug":"only-the-key-and-discriminator-parts-of-an-any","errorCode":null,"errorMessage":"Only the key and discriminator parts of an '@Any' mapping may be dereferenced","messagePattern":"Only the key and discriminator parts of an '@Any' mapping may be dereferenced","errorType":"exception","errorClass":"UnsupportedMappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java","lineNumber":63,"sourceCode":"\t\t);\n\t}\n\n\t@Override\n\tpublic @Nullable SqmPathSource<?> findSubPathSource(String name) {\n\t\treturn switch ( name ) {\n\t\t\tcase AnyKeyPart.KEY_NAME ->\n\t\t\t\t// standard id() function\n\t\t\t\t\tkeyPathSource;\n\t\t\tcase AnyDiscriminatorPart.ROLE_NAME ->\n\t\t\t\t// standard type() function\n\t\t\t\t\tdiscriminatorPathSource;\n\t\t\tcase \"id\" ->\n\t\t\t\t// deprecated HQL .id syntax\n\t\t\t\t\tkeyPathSource;\n\t\t\tcase \"class\" ->\n\t\t\t\t// deprecated HQL .class syntax\n\t\t\t\t\tdiscriminatorPathSource;\n\t\t\tdefault -> throw new UnsupportedMappingException(\n\t\t\t\t\t\"Only the key and discriminator parts of an '@Any' mapping may be dereferenced\" );\n\t\t};\n\t}\n\n\t@Override\n\tpublic SqmPath<J> createSqmPath(SqmPath<?> lhs, @Nullable SqmPathSource<?> intermediatePathSource) {\n\t\treturn new SqmAnyValuedSimplePath<>(\n\t\t\t\tPathHelper.append( lhs, this, intermediatePathSource ),\n\t\t\t\tpathModel,\n\t\t\t\tlhs,\n\t\t\t\tlhs.nodeBuilder()\n\t\t);\n\t}\n}\n","sourceCodeStart":45,"sourceCodeEnd":78,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java#L45-L78","documentation":"Error \"Only the key and discriminator parts of an '@Any' mapping may be dereferenced\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a query path dereferences a part of an @Any mapping other than its key or discriminator.","commonSituations":"See trigger scenarios.","solutions":["In the query, dereference only the key or discriminator part of the @Any mapping; load the target entity separately for further navigation."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}