{"record":{"id":"a58d3acaaf6e6fa6","repo":"hibernate/hibernate-orm","slug":"all-query-parts-in-a-query-group-must-have-the-sam-a58d3a","errorCode":null,"errorMessage":"All query parts in a query group must have the same join fetches in the same order","messagePattern":"All query parts in a query group must have the same join fetches in the same order","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java","lineNumber":196,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new AssertionFailure( \"Unrecognized SqmQueryPart subtype\" );\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void validateFetchesMatch(SqmFrom<?, ?> firstFrom, SqmFrom<?, ?> from) {\n\t\tfinal var firstJoinIter = firstFrom.getSqmJoins().iterator();\n\t\tfinal var joinIter = from.getSqmJoins().iterator();\n\t\twhile ( firstJoinIter.hasNext() ) {\n\t\t\tfinal SqmJoin<?, ?> firstSqmJoin = firstJoinIter.next();\n\t\t\tif ( firstSqmJoin instanceof SqmAttributeJoin<?, ?> firstAttrJoin ) {\n\t\t\t\tif ( firstAttrJoin.isFetched() ) {\n\t\t\t\t\tfinal var matchingAttrJoin = findFirstFetchJoin( joinIter );\n\t\t\t\t\tif ( matchingAttrJoin == null || firstAttrJoin.getModel() != matchingAttrJoin.getModel() ) {\n\t\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\t\"All query parts in a query group must have the same join fetches in the same order\"\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tvalidateFetchesMatch( firstAttrJoin, matchingAttrJoin );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// At this point, the other iterator should only contain non-fetch joins\n\t\twhile ( joinIter.hasNext() ) {\n\t\t\tif ( joinIter.next() instanceof SqmAttributeJoin<?, ?> attrJoin\n\t\t\t\t\t&& attrJoin.isFetched() ) {\n\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\"All query parts in a query group must have the same join fetches in the same order\"\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java#L178-L214","documentation":"Error \"All query parts in a query group must have the same join fetches in the same order\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Query parts joined by set operations declare join fetches that differ in content or order.","commonSituations":"Adding a fetch join in only one UNION branch; mirror the same fetches in the same order in every part.","solutions":["Give every query part in the group the same join fetches, declared in the same order.","Remove the join fetch from the parts that do not have it, or add the identical fetch to all parts.","Move the fetch out of the grouped queries if it is only needed on one part, and fetch it in a separate query."],"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"}