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;
}
And
@Entity
public class Price {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Long Id;
@ManyToOne
@JoinColumn(name="outletVareityId")
private OutletProductVariety outletVariety;
private Double price;
}
How can I get a List of prices rather then PersistentBag?
Have a look at Hibernates PersistentBag
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;
It implements java.util.List;
so it is basically a List
and wraps your List internally
It is just Hibernates way to represent your List.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With