ORDER BY in Criteria API for a computed column name (by alias)

后端 未结 4 950
广开言路
广开言路 2021-01-26 04:15

Having a situation where my java code is symbolic to query -

  SELECT CUSTOMER_ID,
         CUSTOMER_NAME,
         CASE
             WHEN COUNT (DISTINCT CARD_ID         


        
4条回答
  •  猫巷女王i
    2021-01-26 05:15

    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)));
    

提交回复
热议问题