title: Does Hibernate support UNION ALL?
body: <p>I'm a partial UI developer, right now I need to turn into Hibernate development. Today I occurred a problem in HQL when I'm trying to use UNION ALL, here is the HQL:</p>
  
  <pre><code>SELECT COUNT(DISTINCT users.userId) AS totalSize FROM (SELECT DISTINCT 
  d1.sponsor.id AS userId FROM Dating d1 WHERE d1.invitee.id = ? UNION ALL 
  SELECT DISTINCT d2.invitee.id AS userId FROM Dating d2 WHERE d2.sponsor.id = ?) 
  AS users 
  </code></pre>
  
  <p>It shows error like this:</p>
  
  <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 55
  </code></pre>
  
  <p>And then I tried translate this HQL to raw SQL:</p>
  
  <pre><code>SELECT COUNT(DISTINCT users.userId) AS totalSize FROM (SELECT DISTINCT 
  d1.sponsorId AS userId FROM mmy_dating d1 WHERE d1.inviteeId = 6 UNION 
  ALL SELECT DISTINCT d2.inviteeId AS userId FROM mmy_dating d2 WHERE 
  d2.sponsorId = 6) AS users;
  </code></pre>
  
  <p>It normally shows the correct result, so I was thinking if Hibernate doesn't support UNION ALL syntax?</p>
  
  <p>Thanks in advance.</p>