{"record":{"id":"3f7b0780787d176a","repo":"hibernate/hibernate-orm","slug":"all-query-parts-in-a-query-group-must-have-the-sam","errorCode":null,"errorMessage":"All query parts in a query group must have the same arity","messagePattern":"All query parts in a query group must have the same arity","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java","lineNumber":164,"sourceCode":"\t\tfinal int firstSelectionSize = firstSelections.size();\n\t\tfinal List<SqmTypedNode<?>> typedNodes = new ArrayList<>( firstSelectionSize );\n\t\tfor ( int i = 0; i < firstSelectionSize; i++ ) {\n\t\t\ttypedNodes.add( firstSelections.get( i ).getSelectableNode() );\n\t\t}\n\t\tvalidateQueryGroupFetchStructure( typedNodes );\n\t}\n\n\tprivate void validateQueryGroupFetchStructure(List<? extends SqmTypedNode<?>> typedNodes) {\n\t\tfinal int firstSelectionSize = typedNodes.size();\n\t\tfor ( int i = 0; i < queryParts.size(); i++ ) {\n\t\t\tfinal SqmQueryPart<T> queryPart = queryParts.get( i );\n\t\t\tif ( queryPart instanceof SqmQueryGroup<?> queryGroup ) {\n\t\t\t\tqueryGroup.validateQueryGroupFetchStructure( typedNodes );\n\t\t\t}\n\t\t\telse if ( queryPart instanceof SqmQuerySpec<?> querySpec ) {\n\t\t\t\tfinal var selections = querySpec.getSelectClause().getSelections();\n\t\t\t\tif ( firstSelectionSize != selections.size() ) {\n\t\t\t\t\tthrow new SemanticException( \"All query parts in a query group must have the same arity\" );\n\t\t\t\t}\n\t\t\t\tfor ( int j = 0; j < firstSelectionSize; j++ ) {\n\t\t\t\t\tfinal SqmTypedNode<?> firstSqmSelection = typedNodes.get( j );\n\t\t\t\t\tfinal JavaType<?> firstJavaType = firstSqmSelection.getNodeJavaType();\n\t\t\t\t\tfinal JavaType<?> nodeJavaType = selections.get( j ).getNodeJavaType();\n\t\t\t\t\tif ( nodeJavaType != null && firstJavaType != null && firstJavaType != nodeJavaType ) {\n\t\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\t\"Select items of the same index must have the same java type across all query parts\"\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( firstSqmSelection instanceof SqmFrom<?, ?> firstFrom ) {\n\t\t\t\t\t\tfinal var from = (SqmFrom<?, ?>) selections.get( j ).getSelectableNode();\n\t\t\t\t\t\tvalidateFetchesMatch( firstFrom, from );\n\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\" );","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java#L146-L182","documentation":"Error \"All query parts in a query group must have the same arity\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Query parts combined with set operations (UNION/INTERSECT/EXCEPT) select a different number of items.","commonSituations":"A UNION of two criteria queries where one selects extra columns; align the select lists of all query parts.","solutions":["Ensure every query part in the UNION/INTERSECT/EXCEPT group selects the same number of items.","Count the selections of each query part and align them (add/remove selections so arities match).","If one part intentionally selects fewer columns, pad it with null literals or dummy expressions of the right type."],"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"}