I'm getting Hibernate's message that I have an "Error in named query".
Below is the HQL statement I'm trying to execute.
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
I think the problem might be related to the sum
function in the outer query or the union
operator but I haven't been able to narrow it down.
Does anyone have any ideas?