You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sort is applied to every arm of a parenthesized HQL set operation #4342
When a sorted query is applied to an HQL query using a parenthesized set operation, HqlSortedQueryTransformer.visitNestedQueryExpression re-enters visitOrderedQuery(ctx), which applies the transformer's Sort again at every nesting level — although visitQueryExpression explicitly passes Sort.unsorted() to non-last arms.
On main, sorting
(SELECT tb FROM Test tb WHEREtb.type='A') UNION (SELECT tb FROM Test tb WHEREtb.type='B')
by tb.Type produces:
(SELECT tb FROM Test tb WHEREtb.type='A'order bytb.Typeasc)UNION (SELECT tb FROM Test tb WHEREtb.type='B'order bytb.Typeasc) order bytb.Typeasc
The ORDER BY is applied three times. When the arms use different aliases — e.g. (select u from User u) union (select v from Visitor v) with Sort.by("name") — the order by u.name injected into the second arm references an unknown alias and Hibernate rejects the query; even with equal aliases the per-arm ordering changes set-operation semantics.
Expected: Sort is applied exactly once, at the outermost query level, matching the invariant already asserted for FROM-subqueries. I will submit a PR with a fix and tests.
Activity
Polishing.
Apply `ORDER BY` only to the outermost query for parenthesized HQL se…
Polishing.
Apply `ORDER BY` only to the outermost query for parenthesized HQL se…
Polishing.
Apply `ORDER BY` only to the outermost query for parenthesized HQL se…