Having a situation where my java code is symbolic to query -
SELECT CUSTOMER_ID,
CUSTOMER_NAME,
CASE
WHEN COUNT (DISTINCT CARD_ID
It seems this is not possible with the JPA Criteria API and you will have to fallback to using JPQL/HQL instead.
Using the Criteria API, you need to order by the caseSelect
expression. I gave it a try and it works fine with Hibernate 5.4. Which version do you use?
This is fairly not possible and just feels like a case missed by JPA. Though if using hibernate API it is possible. But, my workaround was -
Now in the order by you could mention the column name by View.column_name.
I faced a similar situation...
query.multiselect(root, computedColumn);
query.orderBy(new Order[]{filterDTO.getSortAsc() ? cb.asc(cb.literal(2)) : cb.desc(cb.literal(2))});
I my case computedColumn is Subquery...I did not manage to make it work by column alias but it seems to work by column index returned in the tupple so I guess in your code it should work by index 1
query.orderBy(cb.asc(cb.literal(1)));