hibernate/hibernate-orm · error · SemanticException
All query parts in a query group must have the same arity
Error message
All query parts in a query group must have the same arity
What it means
Error "All query parts in a query group must have the same arity" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmQueryGroup.java:164
final int firstSelectionSize = firstSelections.size();
final List<SqmTypedNode<?>> typedNodes = new ArrayList<>( firstSelectionSize );
for ( int i = 0; i < firstSelectionSize; i++ ) {
typedNodes.add( firstSelections.get( i ).getSelectableNode() );
}
validateQueryGroupFetchStructure( typedNodes );
}
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" );View on GitHub (pinned to fad1729dce)
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.
When it happens
Trigger: Query parts combined with set operations (UNION/INTERSECT/EXCEPT) select a different number of items.
Common situations: A UNION of two criteria queries where one selects extra columns; align the select lists of all query parts.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3f7b0780787d176a.
Report an issue: GitHub.