【发布时间】:2014-08-31 18:10:42
【问题描述】:
以下是我的代码这里我使用多个列表从数据库中获取数据。 从 hql 查询中获取数据时显示异常。
Pojo 类
public class BillDetails implements java.io.Serializable {
private Long billNo;
// other fields
@LazyCollection(LazyCollectionOption.FALSE)
private List<BillPaidDetails> billPaidDetailses = new ArrayList<BillPaidDetails>();
private Set productReplacements = new HashSet(0);
@LazyCollection(LazyCollectionOption.FALSE)
private List<BillProduct> billProductList = new ArrayList<BillProduct>();
//getter and setter
}
hmb.xml 文件
<class name="iland.hbm.BillDetails" table="bill_details" catalog="retail_shop">
<id name="billNo" type="java.lang.Long">
<column name="bill_no" />
<generator class="identity" />
</id>
<bag name="billProductList" table="bill_product" inverse="true" lazy="false" fetch="join">
<key>
<column name="bill_no" not-null="true" />
</key>
<one-to-many class="iland.hbm.BillProduct" />
</bag>
<bag name="billPaidDetailses" table="bill_paid_details" inverse="true" lazy="false" fetch="select">
<key>
<column name="bill_no" not-null="true" />
</key>
<one-to-many class="iland.hbm.BillPaidDetails" />
</bag>
<set name="productReplacements" table="product_replacement" inverse="true" lazy="false" fetch="join">
<key>
<column name="bill_no" not-null="true" />
</key>
<one-to-many class="iland.hbm.ProductReplacement" />
</set>
</class>
Hql查询
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
如何解决这个问题
【问题讨论】:
-
您是否尝试过将列表更改为集合?
-
这篇文章可能对你有帮助:blog.eyallupu.com/2010/06/…
-
BillProduct 上的唯一 id 属性的名称是什么?
-
Insted 的列表集正在工作。但我想处理列表
-
你真的需要使用列表吗?
标签: java hibernate jpa hibernate-mapping bag