title: Custom SQL for Order in JPA Criteria API
body: <p>I'm switching from deprecated (unfortunately) Hibernate Criteria API to JPA Criteria API. We have a custom Order (from Hibernate) interface implementation to redefine SQL generated for it. The case is quite sophisticated as we need to use a giant <strong>SELECT</strong> with subqueries. We implemented <code>toSqlString</code> method of the interface to return this huge SQL and we need a way to migrate it to <code>JPA Criteria API</code>.</p>
  
  <p>The question is: is there a way in JPA Criteria API to redefine the SQL generated? Or is there a weird way to use Hibernate Order with JPA Criteria API?</p>
  
  <p>Thank you!</p>
  
  <p><strong>UPDATE</strong> Although @Tobias Liefke suggestion is quite interesting, my SQL varies too much to create a function class per SQL. I tried implementing a single function class and passing the SQL there as an argument but that didn't work (the rendered SQL was enclosed in single quotes thus it was sent to the database as parameter and not as part of the generated query)</p>