I was reading up on this exception:
Code:
org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
And I now understand why this is:
http://www.jroller.com/eyallupu/entry/hibernate_exception_simultaneously_fetch_multiple
However, if you take Eyal Lupu his example, you'll see that indeed the join duplicated the "child2-1" entry (while parent-1 only has one child2-1 relation).
Now, the instance loaded in memory will have two times the same reference (so the list will contain two entries which are ==).
Second, the two entries all have the same primary key (id).
My question is; why is it that hibernte cannot determine that there is only one cild2-1 entry?
If it used a 'distinct root entity projection' for example it would only retrieve one object...
Second, the solution is to add an index column.
But this is not really different from having the id's on the table in the first place no?
I don't understand why adding an index column solves this problem why there is allready a column that can indicate the uniqueness of a row (the primary key).
The index column is abused here for uniqueness instead of order.
So I do understand that it becomes more difficult to filter out the duplicates here, but why can't it be done without the id column?