title: JPA With CriteriaQuery and ORDER BY multiplication of values
body: <p>I gave up on finding solution for my previous question: <a href="https://stackoverflow.com/questions/55118255/spring-data-order-by-multiplication-of-columns">Spring data - Order by multiplication of columns</a> because I couldn't find any way to achieve it that way.</p>
  
  <p>The problem is, I am using <code>EntityManager</code> with <code>CriteriaQuery</code>, and I am trying to find a way to put there an ORDER BY clause, but with multiplication of two columns.
  Ex. you store in DB amount and price per unit of something, and you want to order it by total price (amount * unitPrice).</p>
  
  <p>But when I try <code>cq.orderBy(cb.asc(r.get("amount * unitPrice")));</code>, even when both attributes are in my DTO, I always get <code>java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [amount * unitPrice]</code>. Obviously, I know why I get that exception, but I can't find any workaround to run such a query.</p>
  
  <p>I can't use named query as my query takes a filter that I apply to it dynamically -> I can't place "<code>where id in ()</code>", as user can not select any ID, meaning he wants to show all of them and my named query would return nothing obviously. And of course I can't affort sorting it in backend as there are just so many records.</p>
  
  <p>I'd been searching for something to achieve it for so long and haven't found any solution and I can't believe it's not possible.</p>