title: Hibernate HQL Query Subselects or Joins
body: <p>In a custom blog platform with User(s), Post(s), and Message(s).
  I know how to do an HQL query with distinct Users and their Post count. Also distinct Users and their Message count.</p>
  
  <p>But if I combine the two with "inner join" technique I get the same count for Posts and Messages. I understand why this is happening because of the joins. How could I do sub-selects in the HQL to get the two counts as separately but as one trip to the database?</p>
  
  <p>Here is an example of the last HQL query I tried.</p>
  
  <pre><code>   select u.username, count(m), count(p) from User as u 
     inner join u.Messages as m
     inner join u.Posts as p
     group by u.id 
     order by count(m) desc
  </code></pre>
  
  <p>Note: I will be changing the order by based off of an option on a web page.</p>