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?
You can't use a subquery after From
clause in HQL. My suggestion is that you can use native query
. For more detail you should look at following link :- Hibernate Query Limitation
Hibernate does not support union
.
A feature request for that is open for a decade.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.