title: How to use subquery into "from" clause in hibernate?
body: <p>I have three tables: <code>class</code>, <code>student</code>, and <code>teacher</code></p>
  
  <pre><code>table class
  {
      class_id(PK)
  }
  
  table student
  {
      student_id(PK)
      class_id(PK+FK)
  }
  
  table teacher
  {
      teacher_id(PK)
      class_id(PK+FK)
  }
  </code></pre>
  
  <p>I have a query in SQL, which works fine.</p>
  
  <pre><code>SELECT data.class_id, count(data.class_id) AS count
  FROM ((SELECT class_id FROM student)
          union all
          (SELECT class_id FROM teacher)) AS data
  GROUP BY data.user_id
  ORDER BY count desc
  </code></pre>
  
  <p>The query contains sub query in the <strong>from clause</strong> and <strong>union operation</strong>.
  I unable to convert it to the HQL.</p>
  
  <p>please give me the efficient HQL query from the above SQL query.</p>