I’m not sure if the title fits. I had trouble finding a good one. This bug leads to multiple duplicates appear in the list of a OneToMany relation that was initialized manually in order to prevent N+1 query problem. There are three entities, A, B and C. A <11> B B <1N> C A has one B, B has multiple C. Loading is configured as lazy. Given situation: I have 4 {{A}}which all point to the same B. This {{B}}has two C. So if I do {{a.getB().getCList()}}the size should be 2. This works out of the box with lazy loading. However, if I add the following query, in order to load all {{C}}into the cache and a prevent N+1 query problem, then suddenly each {{B}}has eight entries of C.
It doesn’t make a difference if I remove the distinct and query hint. {{aList}}is just the list of the four a entities. A test case is attached. |