title: JPA criteria query, order on class
body: <p>Is there a way with JPA criteria queries to order on <strong>class</strong>? Imagine the following domain objects:</p>
  
  <pre><code>abstract class Hobby { ... }
  class Coding extends Hobby { ... }
  class Gaming extends Hobby { ... }
  </code></pre>
  
  <p>Using regular QL I was able to do</p>
  
  <pre><code>from Hobby h order by h.class
  </code></pre>
  
  <p>But when I apply the same logic on a criteria query, the runtime exception "unknown attribute" occurs.</p>
  
  <pre><code>CriteriaQuery&lt;Hobby&gt; criteriaQuery = builder.createQuery(Hobby.class);
  Root&lt;Hobby&gt; hobbyRoot = criteriaQuery.from(Hobby.class);
  criteriaQuery.orderBy(builder.asc(hobbyRoot.get("class"));
  List&lt;Hobby&gt; hobbies = entityManager.createQuery(criteriaQuery).getResultList();
  </code></pre>
  
  <p>JPA implementation used: Hibernate-EntityManager v3.5.5-Final</p>