Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags
I think a newer version of hibernate (supporting JPA 2.0) should handle this. But otherwise you can work it around by annotating the collection fields with:
@LazyCollection(LazyCollectionOption.FALSE)
Remember to remove the fetchType
attribute from the @*ToMany
annotation.
But note that in most cases a Set<Child>
is more appropriate than List<Child>
, so unless you really need a List
- go for Set
But remind that with using sets you won't eliminate the underlaying Cartesian Product as described by Vlad Mihalcea in his answer!
Simply change from List
type to Set
type.
But remind that you won't eliminate the underlaying Cartesian Product as described by Vlad Mihalcea in his answer!
Add a Hibernate-specific @Fetch annotation to your code:
@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
private List<Child> childs;
This should fix the issue, related to Hibernate bug HHH-1718