title: Order query results with Criteria API by something that is NOT a database field
body: <p>I'm using Criteria API to fetch sorted data from my database.
  Sorting like this works fine:</p>
  <pre><code>Path&lt;Data&gt; data = // initialize;
  String sortField = // initialize name of field to sort by;
  Expression&lt;?&gt; sortExpression = data.get(sortField);
  criteriaQuery.orderBy(criteriaBuilder.desc(sortExpression));
  </code></pre>
  <p>This way, I can order my results by field content. But how can I order by something else?</p>
  <p>In my example, I have a database field <code>data.user_id</code> that contains a (nullable) user ID. While the query will fetch the ID, I want to sort not by the ID itself (the numerical value), but by the three categories &quot;the ID is null&quot;, &quot;the ID is mine&quot;, &quot;the ID is someone elses&quot;. I have access to the ID that is &quot;mine&quot; in my service method, but how can I sort like that?</p>