{"record":{"id":"349dea0c6daf6f76","repo":"hibernate/hibernate-orm","slug":"return-join-did-not-specify-alias-ownertab","errorCode":null,"errorMessage":"<return-join/> did not specify alias [\" + ownerTableAlias + \".\" + propertyPath + \"]","messagePattern":"<return-join/> did not specify alias \\[\" \\+ ownerTableAlias \\+ \"\\.\" \\+ propertyPath \\+ \"\\]","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java","lineNumber":733,"sourceCode":"\t\t\t\tString registrationName,\n\t\t\t\tMetadataBuildingContext context) {\n\t\t\tthis.joinDescriptorsAccess = joinDescriptorsAccess;\n\t\t\tthis.fetchParentByAliasAccess = fetchParentByAliasAccess;\n\t\t\tfinal String fullPropertyPath = hbmJoinReturn.getProperty();\n\t\t\tfinal int firstDot = fullPropertyPath.indexOf( '.' );\n\t\t\tif ( firstDot < 1 ) {\n\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\"Illegal <return-join/> property attribute: '\" + fullPropertyPath + \"'\"\n\t\t\t\t\t\t+ \" - should be in the form '{ownerAlias.joinedPropertyPath}'\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\townerTableAlias = fullPropertyPath.substring( 0, firstDot );\n\n\t\t\tpropertyPath = fullPropertyPath.substring( firstDot + 1 );\n\t\t\ttableAlias = hbmJoinReturn.getAlias();\n\t\t\tif ( tableAlias == null ) {\n\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\"<return-join/> did not specify alias [\" + ownerTableAlias + \".\" + propertyPath + \"]\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlockMode = hbmJoinReturn.getLockMode();\n\t\t\tpropertyFetchDescriptors = extractPropertyFetchDescriptors(\n\t\t\t\t\thbmJoinReturn.getReturnProperty(),\n\t\t\t\t\tthis,\n\t\t\t\t\tregistrationName,\n\t\t\t\t\tcontext\n\t\t\t);\n\t\t}\n\n\t\t@Override\n\t\tpublic String getFetchablePath() {\n\t\t\treturn propertyPath;\n\t\t}\n","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java#L715-L751","documentation":"After splitting the <return-join/> property attribute into owner alias and property path, the JoinDescriptor constructor reads hbmJoinReturn.getAlias() and throws this MappingException when no alias attribute was supplied. The join's alias is what nested <return-property/> elements and downstream joins reference, so it is mandatory.","triggerScenarios":"<return-join property=\"o.items\"/> without an alias attribute; alias dropped when copying a join block; generated mappings that omit the attribute on joins.","commonSituations":"Hand-written or merged hbm.xml files; teams adding joins quickly during native-query tuning.","solutions":["Add a unique alias: <return-join alias=\"i\" property=\"o.items\"/>.","Ensure the alias is distinct from all other aliases in the same result set mapping and is the one referenced by any nested return-property paths."],"exampleFix":"<!-- before -->\n<return-join property=\"o.items\"/>\n\n<!-- after -->\n<return-join alias=\"i\" property=\"o.items\"/>","handlingStrategy":"validation","validationCode":"String alias = returnJoinElement.attributeValue( \"alias\" );\nif ( alias == null || alias.isBlank() ) {\n    throw new IllegalStateException( \"return-join property=\" + returnJoinElement.attributeValue( \"property\" ) + \" needs an alias\" );\n}","typeGuard":null,"tryCatchPattern":"catch ( MappingException e ) {\n    if ( e.getMessage().startsWith( \"<return-join/> did not specify alias\" ) ) {\n        // message names ownerAlias.propertyPath; add the alias attribute to that join\n    }\n}","preventionTips":["Write joins with all three attributes (alias, property) from a checklist.","Lint hbm.xml in CI so missing attributes fail before runtime."],"tags":["hibernate","hbm-xml","native-query","return-join","boot"],"backgroundTag":"missing-result-alias","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}