hibernate/hibernate-orm · error · SemanticException
Select items of the same index must have the same java type
Error message
Select items of the same index must have the same java type across all query parts
What it means
Error "Select items of the same index must have the same java type across all query parts" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java:171
private void validateQueryGroupFetchStructure(List<? extends SqmTypedNode<?>> typedNodes) {
final int firstSelectionSize = typedNodes.size();
for ( int i = 0; i < queryParts.size(); i++ ) {
final SqmQueryPart<T> queryPart = queryParts.get( i );
if ( queryPart instanceof SqmQueryGroup<?> queryGroup ) {
queryGroup.validateQueryGroupFetchStructure( typedNodes );
}
else if ( queryPart instanceof SqmQuerySpec<?> querySpec ) {
final var selections = querySpec.getSelectClause().getSelections();
if ( firstSelectionSize != selections.size() ) {
throw new SemanticException( "All query parts in a query group must have the same arity" );
}
for ( int j = 0; j < firstSelectionSize; j++ ) {
final SqmTypedNode<?> firstSqmSelection = typedNodes.get( j );
final JavaType<?> firstJavaType = firstSqmSelection.getNodeJavaType();
final JavaType<?> nodeJavaType = selections.get( j ).getNodeJavaType();
if ( nodeJavaType != null && firstJavaType != null && firstJavaType != nodeJavaType ) {
throw new SemanticException(
"Select items of the same index must have the same java type across all query parts"
);
}
if ( firstSqmSelection instanceof SqmFrom<?, ?> firstFrom ) {
final var from = (SqmFrom<?, ?>) selections.get( j ).getSelectableNode();
validateFetchesMatch( firstFrom, from );
}
}
}
else {
throw new AssertionFailure( "Unrecognized SqmQueryPart subtype" );
}
}
}
private void validateFetchesMatch(SqmFrom<?, ?> firstFrom, SqmFrom<?, ?> from) {
final var firstJoinIter = firstFrom.getSqmJoins().iterator();
final var joinIter = from.getSqmJoins().iterator();View on GitHub (pinned to fad1729dce)
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.
When it happens
Trigger: Query parts in a set-operation group select items whose Java types differ at the same select-list position.
Common situations: Selecting a String in one UNION branch and an Integer at the same index in another; coerce or align the types.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/f40df821c99cc63e.
Report an issue: GitHub.