{"record":{"id":"d83ea26d110defab","repo":"hibernate/hibernate-orm","slug":"query-specified-join-fetching-but-the-owner-of-th","errorCode":null,"errorMessage":"Query specified join fetching, but the owner of the fetched association was not present in the select list [%s]","messagePattern":"Query specified join fetching, but the owner of the fetched association was not present in the select list \\[(.+?)\\]","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQuerySpec.java","lineNumber":631,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t\tfor ( var sqmTreat : sqmJoin.getSqmTreats() ) {\n\t\t\t\tif ( sqmTreat instanceof SqmAttributeJoin<?, ?> attributeJoin ) {\n\t\t\t\t\tif ( attributeJoin.isFetched() ) {\n\t\t\t\t\t\tassertFetchOwner( selectedFromSet, attributeJoin.getLhs(), attributeJoin );\n\t\t\t\t\t\t// Only need to check the first level\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvalidateFetchOwners( selectedFromSet, sqmTreat );\n\t\t\t}\n\t\t\tvalidateFetchOwners( selectedFromSet, sqmJoin );\n\t\t}\n\t}\n\n\tprivate void assertFetchOwner(Set<SqmFrom<?, ?>> selectedFromSet, SqmFrom<?, ?> owner, SqmJoin<?, ?> fetchJoin) {\n\t\tif ( !selectedFromSet.contains( owner ) ) {\n\t\t\tthrow new SemanticException(\n\t\t\t\t\t\"Query specified join fetching, but the owner \" +\n\t\t\t\t\t\t\t\"of the fetched association was not present in the select list \" +\n\t\t\t\t\t\t\t\"[\" + fetchJoin.asLoggableText() + \"]\"\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void appendHqlString(StringBuilder hql, SqmRenderContext context) {\n\t\tfinal var selections = selectClause.getSelections();\n\t\tif ( !selections.isEmpty() ) {\n\t\t\thql.append( \"select \" );\n\t\t\tif ( selectClause.isDistinct() ) {\n\t\t\t\thql.append( \"distinct \" );\n\t\t\t}\n\t\t\tselections.get( 0 ).appendHqlString( hql, context );\n\t\t\tfor ( int i = 1; i < selections.size(); i++ ) {\n\t\t\t\thql.append( \", \" );","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQuerySpec.java#L613-L649","documentation":"Error \"Query specified join fetching, but the owner of the fetched association was not present in the select list [%s]\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A join fetch is declared but the owner of the fetched association is not among the selected roots.","commonSituations":"Fetching an association of a root that is not returned (JPA restriction); select the owner or drop the fetch.","solutions":["Include the owner of the fetched association in the select list (select the root/entity that owns the join fetch).","Remove the join fetch if the owning entity is not selected, and load the association lazily or via a separate query.","Use an entity graph or a dedicated fetch query instead of join fetching an association whose owner is not returned."],"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"}