{"record":{"id":"c55db5d80fc8844e","repo":"hibernate/hibernate-orm","slug":"could-not-locate-join-return-owner-by-alias-o","errorCode":null,"errorMessage":"Could not locate join-return owner by alias [\" + ownerTableAlias + \"] for join path [\" + propertyPath + \"]","messagePattern":"Could not locate join-return owner by alias \\[\" \\+ ownerTableAlias \\+ \"\\] for join path \\[\" \\+ propertyPath \\+ \"\\]","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java","lineNumber":806,"sourceCode":"\t\t\t\t\t\townerTableAlias,\n\t\t\t\t\t\ttableAlias,\n\t\t\t\t\t\tkeyColumnNames,\n\t\t\t\t\t\tlockMode,\n\t\t\t\t\t\tthisAsParentMemento,\n\t\t\t\t\t\tfetchDescriptorMap,\n\t\t\t\t\t\t(Fetchable) thisAsParentMemento.getFetchableContainer()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn memento;\n\t\t}\n\n\t\t@Override\n\t\tpublic HbmFetchParentMemento resolveParentMemento(ResultSetMappingResolutionContext resolutionContext) {\n\t\t\tif ( thisAsParentMemento == null ) {\n\t\t\t\tfinal var hbmFetchParent = fetchParentByAliasAccess.get().get( ownerTableAlias );\n\t\t\t\tif ( hbmFetchParent == null ) {\n\t\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\t\"Could not locate join-return owner by alias [\" + ownerTableAlias + \"] for join path [\" + propertyPath + \"]\"\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tfinal var ownerMemento = hbmFetchParent.resolveParentMemento( resolutionContext );\n\n\t\t\t\tfinal var parts = split( \".\", propertyPath );\n\t\t\t\tNavigablePath navigablePath =\n\t\t\t\t\t\townerMemento.getFetchableContainer() instanceof PluralAttributeMapping\n\t\t\t\t\t\t\t\t? ownerMemento.getNavigablePath().append( CollectionPart.Nature.ELEMENT.getName() )\n\t\t\t\t\t\t\t\t: ownerMemento.getNavigablePath();\n\t\t\t\tnavigablePath = navigablePath.append( parts[ 0 ] );\n\t\t\t\tFetchableContainer fetchable = (FetchableContainer)\n\t\t\t\t\t\townerMemento.getFetchableContainer().findSubPart( parts[ 0 ], null );\n\n\t\t\t\tfor ( int i = 1; i < parts.length; i++ ) {\n\t\t\t\t\tnavigablePath = navigablePath.append( parts[ i ] );\n\t\t\t\t\tfetchable = (FetchableContainer) fetchable.findSubPart( parts[ i ], null );","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java#L788-L824","documentation":"To resolve a <return-join/>, Hibernate looks up the owner side via fetchParentByAliasAccess.get().get(ownerTableAlias), the map of aliases registered by <return/> and <return-collection/> elements. When the alias prefix of the property attribute is not in that map, hbmFetchParent is null and this MappingException names the missing alias and the join path. The join references an owner that was never declared (or is spelled differently).","triggerScenarios":"<return-join property=\"ord.items\" .../> while the owner <return> declares alias=\"o\"; owner return missing entirely (only joins in the query, see error 756); case mismatch between the alias in property and the alias attribute.","commonSituations":"Renaming an alias in the root return but not in join property attributes; deleting a root return while leaving its joins; copy-pasting joins between query mappings with different alias conventions.","solutions":["Make the alias before the dot exactly match an alias declared by a <return/> or <return-collection/> in the same mapping.","If no owner return exists, add one, e.g. <return alias=\"o\" entity-name=\"com.acme.Order\"/>.","Watch case sensitivity: 'Ord' does not match 'o' or 'O' beyond exact spelling."],"exampleFix":"<!-- before: no return declares alias 'ord' -->\n<sql-query name=\"q\">\n    <return alias=\"o\" entity-name=\"com.acme.Order\"/>\n    <return-join alias=\"i\" property=\"ord.items\"/>\n</sql-query>\n\n<!-- after -->\n<sql-query name=\"q\">\n    <return alias=\"o\" entity-name=\"com.acme.Order\"/>\n    <return-join alias=\"i\" property=\"o.items\"/>\n</sql-query>","handlingStrategy":"validation","validationCode":"// collect aliases declared by root returns, then check each join's owner prefix:\nSet<String> declared = rootReturns.stream().map( r -> r.attributeValue( \"alias\" ) ).collect( toSet() );\nfor ( Element join : returnJoinElements ) {\n    String owner = join.attributeValue( \"property\" ).split( \"\\\\.\" )[0];\n    if ( !declared.contains( owner ) ) {\n        throw new IllegalStateException( \"Join owner alias '\" + owner + \"' is not declared by any return/collection return\" );\n    }\n}","typeGuard":null,"tryCatchPattern":"catch ( MappingException e ) {\n    if ( e.getMessage().startsWith( \"Could not locate join-return owner by alias\" ) ) {\n        // message names the bad alias and join path; align it with the root return's alias attribute\n    }\n}","preventionTips":["Define the root return first, then copy its alias verbatim into join property prefixes.","After renaming an alias, search the whole query mapping for the old spelling.","Never leave joins whose root return was removed or commented out."],"tags":["hibernate","hbm-xml","native-query","return-join","alias-resolution"],"backgroundTag":"unresolved-alias-reference","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}