title: HQL Error in Named Query
body: <p>I'm getting Hibernate's message that I have an "Error in named query".</p>
  
  <p>Below is the HQL statement I'm trying to execute.</p>
  
  <pre><code>select sum(subtotal)
  from (
        select sum(coalesce(sum(t2.amount), 0) - coalesce(sum(t3.amount), 0)) subtotal
        from submission t1
        left join t1.bills t2
        left join t1.payments t3
        where t1.id = 10
        group by t1.id
  
        union
  
        select sum(coalesce(sum(t2.amount), 0) - coalesce(sum(t3.amount), 0)) subtotal
        from submission t1
        left join t1.otherBills t2
        left join t1.payments t3
        where t1.id = 10
        group by t1.id
  ) a1
  </code></pre>
  
  <p>I think the problem might be related to the <code>sum</code> function in the outer query or the <code>union</code> operator but I haven't been able to narrow it down.</p>
  
  <p>Does anyone have any ideas?</p>