I have the following JPQL in ProductList Entity class which executes as expected.
select DISTINCT new foo.bar.ProductListDTO(p.prodId, " +
CASE WHEN (p.prodId = 'ZCX') THEN CONCAT(p.prodDesc, ' - ', e.userId)
ELSE p.prodDesc END) from
ProductList p LEFT JOIN p.productCatalogueList c where c.userId='ZAM'
ProductListDTO class
public ProductListDTO(String prodId, String prodDesc, String userId) {
this.prodId = prodId;
this.prodName = prodDesc;
this.userId = userId;
}
What I would like to achieve is add ORDER BY
to the query. When p.prodDesc
is added to ORDER BY
clause, I am getting error
not a SELECTed expression
because p.prodDesc is not a selected field. if I add prodName
from ProductListDTO
class then it would
give error The identification variable 'appDesc' is not defined in the FROM clause
.
How can I do ORDER BY
prodDesc as I am using ProductListDTO constructor