hibernate/hibernate-orm · error · UnsupportedOperationException
Full join emulation requires order by expressions to be in t
Error message
Full join emulation requires order by expressions to be in the select list for grouped or distinct queries
What it means
Error "Full join emulation requires order by expressions to be in the select list for grouped or distinct queries" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/sql/ast/spi/FullJoinEmulation.java:172
return fullJoinEmulationBranches != null
&& ( queryPart == fullJoinEmulationQueryGroup
// Some dialects (e.g. Sybase ASE) render ORDER BY outside the query group scope.
|| fullJoinEmulationQueryGroup != null
&& sortSpecifications == fullJoinEmulationQueryGroup.getSortSpecifications() );
}
private void emulateFullJoinWithUnion(QuerySpec querySpec, List<FullJoinEmulationInfo> fullJoins) {
final var sortSpecifications = querySpec.getSortSpecifications();
final List<SortSpecification> preservedSortSpecifications =
sortSpecifications == null ? null : new ArrayList<>( sortSpecifications );
final var extraSelections =
collectFullJoinEmulationExtraSelections( querySpec,
countRenderedSelectItems( querySpec.getSelectClause() ) );
if ( !extraSelections.isEmpty() ) {
if ( querySpec.getSelectClause().isDistinct() // TODO: we could easily remove this limitation
|| !querySpec.getGroupByClauseExpressions().isEmpty()
|| querySpec.getHavingClauseRestrictions() != null ) {
throw new UnsupportedOperationException(
"Full join emulation requires order by expressions to be in the select list for grouped or distinct queries"
);
}
fullJoinEmulationExtraSelections = extraSelections;
}
final var emulationPlan = createFullJoinEmulationPlan( querySpec, fullJoins );
final var queryGroup = emulationPlan.queryGroup();
final var branches = emulationPlan.branches();
copyOrderAndOffsetFetch( querySpec, preservedSortSpecifications, queryGroup );
fullJoinEmulationInfos = fullJoins;
fullJoinEmulationBranches = branches;
fullJoinEmulationQueryGroup = queryGroup;
try {
queryGroup.accept( translator );
}View on GitHub (pinned to fad1729dce)
Solutions
- Add every ORDER BY expression to the select list of the grouped/distinct query so full join emulation can sort on it.
- Remove ORDER BY items that are not in the select list, or drop DISTINCT/GROUP BY if they are not required.
- If the database supports FULL JOIN natively, avoid the emulation path by using a dialect/version that does.
When it happens
Trigger: A full outer join is emulated (via union) on a grouped or distinct query whose ORDER BY expressions are not in the select list.
Common situations: Ordering by a non-selected column with full join on a dialect without native FULL JOIN; add the expression to the select list.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/aa6ec5e5aef59cef.
Report an issue: GitHub.