title: How to use FIELD() function of mysql in JPA
body: <p>My sql query is something like </p>
  
  <p><code>Select * from tableA order by FIELD('ID', 3, 5, 2)</code></p>
  
  <p>How do I implement this in <code>JPA</code> using <strong><code>criteria builder</code></strong>?</p>
  
  <p><em>EDIT</em></p>
  
  <pre><code>List&lt;Integer&gt; ordList = new ArrayList&lt;Integer&gt;();
  ordList.add(3);
  ordList.add(5);
  ordList.add(2);
  public List&lt;Order&gt; getOrderBys(CriteriaBuilder cb, Root&lt;?&gt; root) { 
       List&lt;Order&gt; orders = new ArrayList&lt;Order&gt;();         
             orders.add(cb.function("FIELD", Integer.class, root.get("id"), ordList));
       return orders; 
  }
  </code></pre>
  
  <p>Above is my function which gives list of oders, I want to add only one order same as above sql query. How can I add/call that function in <code>orders.add()</code> method? The above method gives error.</p>