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

后端 未结 4 980
广开言路
广开言路 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条回答
  •  無奈伤痛
    2021-01-26 05:13

    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 -

    1. Created a view which would contain the case expression.
    2. Join the view with my entity (you cannot do a join, but one more query.from(View.class)).
    3. In the where add the ids of View and the entity.

    Now in the order by you could mention the column name by View.column_name.

提交回复
热议问题