Follow on to HHH-1413. Multiple bag fetches were simply disallowed as the resolution to that particular case in the interest of working around that issue.
The correct longer term solution is to not fetch all the bags at once, ideally reverting to subselect fetching for all but one of the bags.
There's a simple, although non-JPA-standard, fix for this.
Specify the following Hibernate annotation alongside your OneToMany field. like so:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
private List<Child> children = new ArrayList<Child>();
Then hibernate will use a subselect rather than a join which is the cause of the issue!
The bulk of the prerequisite work needed for this issue is covered by the LoadPlan work under
True that is one work around. The other is to specify the list index column which is not a Hibernate-specific annotation anymore (JPA offers a standardized one):
The trouble here is the distinction between a List (true List behavior, persistent ordering) versus what Hibernate terms a bag. Specifying the OrderColumn (the "list index" column) makes this a true List
How does @OrderColumn work when the index column is part of the primary key, which is not allowed - at least least according to the JPA?: http://stackoverflow.com/q/10054400/396732 Is it nontheless supported by Hibernate? Otherwise the latter workaround isn't one, which makes reverting to subselects even more important.
I was trying to find a solution that would avoid using:
That's because I don't always want my relationship to be eager. I would like to use `join fetch` in my JPQL query when I need the relationship to be eager.
I have a workaround which is as below:
One of my collections has to be a Set (because a Set is not a Bag). Is it the proper way to work with it? Also, I don't understand why moving to a Set is fixing the issue. Any explanation would be welcome .