hql查询以获取数据和金额总和 [英] hql query to fetch data and sum of amount
本文介绍了hql查询以获取数据和金额总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写查询以从表中获取数据
I am writing query to fetch data from tables
我的hql查询是
SELECT distinct bd FROM BillDetails AS bd
LEFT JOIN FETCH bd.customerDetails AS cd
LEFT JOIN FETCH bd.billProductList AS bpd
LEFT JOIN FETCH bpd.product AS pd
WHERE bd.billNo=:id
AND bd.client.id=:cid
以上查询工作正常
我想编写查询以获取billPaidDetailses
的所有金额字段的总和.
I want to write query to fetch sum of all amount field of billPaidDetailses
.
billPaidDetailses
是BillDetails
类中的列表.
我正在尝试执行以下查询,但无法正常工作
I am trying following query for that but it is not working
String hql = "select distinct bd,sum(bpds.amount) from BillDetails as bd "
+ "left join fetch bd.customerDetails as cd "
+ "left join fetch bd.billProductList as bpd "
+ "left join fetch bpd.product as pd "
+"left join fetch bd.billPaidDetailses as bpds "
+ "where bd.billNo=:id "
+ "and bd.client.id=:cid ";
返回的错误是
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch
multiple bags
推荐答案
查看全文