|
When using the Criteria API adding adding a SubQuery as selection with alias, the alias is ignored when translating to HQL.
Selection selection = someCriteriaSubQuery selection.alias("selectedAttr"); criteriaQuery.select(selection);
The problem is in SubquerySelection.render(RenderingContext) renders the subquery but fails to render its own alias.
In JPQL I can write a query like:
select generatedAlias0.id, (select count(generatedAlias1.id) from SomeEntity as generatedAlias1 ) as someAlias from SomeEntity as generatedAlias0 order by someAlias asc
This allows to order by the count subQuery or any other kind of subquery. If the subquery is added to the order by expression directly (which should not be done anyway), it results in another error.
|