{"record":{"id":"f40df821c99cc63e","repo":"hibernate/hibernate-orm","slug":"select-items-of-the-same-index-must-have-the-same","errorCode":null,"errorMessage":"Select items of the same index must have the same java type across all query parts","messagePattern":"Select items of the same index must have the same java type across all query parts","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java","lineNumber":171,"sourceCode":"\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\" );\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();","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java#L153-L189","documentation":"Error \"Select items of the same index must have the same java type across all query parts\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Query parts in a set-operation group select items whose Java types differ at the same select-list position.","commonSituations":"Selecting a String in one UNION branch and an Integer at the same index in another; coerce or align the types.","solutions":["Make each select item at the same position across all query parts share the same Java type.","Cast or convert mismatched items to a common type (e.g. use a common numeric type or explicit literal type).","Reorder or align the select lists of the query parts so corresponding positions have compatible types."],"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"}