Hibernate返回PersistentBag而不是List [英] Hibernate returning PersistentBag instead of List
问题描述
我有下面的关系b.w下面给出的两个实体,当我从存储库中获取OutletProductVariety对象时,即使使用fetchtype Eager,价格也将以PersistentBag的形式出现,而不是以List的形式出现.
I have following relationship b.w two entities given below ,when I get OutletProductVariety object from repository ,the price is coming in PersistentBag and not as a List even after using fetchtype Eager.
@Entity
public class OutletProductVariety {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@ManyToOne
@JoinColumn(name = "varietyId")
Variety variety;
@OneToMany(mappedBy = "outletVariety", fetch = FetchType.EAGER)
List<Price> price;
}
和
@Entity
public class Price {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Long Id;
@ManyToOne
@JoinColumn(name="outletVareityId")
private OutletProductVariety outletVariety;
private Double price;
}
如何获取价格列表,而不是PersistentBag?
How can I get a List of prices rather then PersistentBag?
推荐答案
看看Hibernates PersistentBag
Have a look at Hibernates PersistentBag
可以包含相同元素的无序,无键集合 多次.奇怪的是,Java collections API没有 包.大多数开发人员似乎都使用列表来表示 包语义,因此Hibernate遵循这种做法.
An unordered, unkeyed collection that can contain the same element multiple times. The Java collections API, curiously, has no Bag. Most developers seem to use Lists to represent bag semantics, so Hibernate follows this practice.
public class PersistentBag extends AbstractPersistentCollection implements List
protected List bag;
它实现了java.util.List;
,因此基本上是一个List
,并在内部包装了列表
It implements java.util.List;
so it is basically a List
and wraps your List internally
这只是Hibernates表示您的列表的方式.
It is just Hibernates way to represent your List.
这篇关于Hibernate返回PersistentBag而不是List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!