java - Fetch joins returning more rows than they should -


i have hit strange problem joins doing. in nutshell if left join correct number of rows. if left join fetch more rows expected.

my entity classes (using pseudocode brevity)

public class 1 {    ...    private set<two> twos; }  public class 2 {    ...    private set<three> threes; }  public class 3 {    ... } 

in relationship have 4 twos in class one , 9 threes in each class two

i expecting have returned 1 class 1 4 twos , in each of these twos 9 threes.

i if use

list<one> res = em.createquery("select o 1 o left join o.twos t left join t.threes o.id = 322", one.class).getresultlist(); list<two> twos = resultlist.get(0).gettwos(); //results in 4 twos - correct  list<one> res = em.createquery("select o 1 o left join fetch o.twos t left join t.threes o.id = 322", one.class).getresultlist(); list<two> twos = resultlist.get(0).gettwos(); //results in 4 twos - correct  list<one> res = em.createquery("select o 1 o left join fetch o.twos t left join fetch.threes o.id = 322", one.class).getresultlist(); list<two> twos = resultlist.get(0).gettwos(); //results in thirty size twos - *incorrect* (is 4 * nine) 

why second fetch cause multiply. having performance problems db want fetch joins try , improve them. doing fetches though seem have lots more results expected.

i using oracle xe db , jpa2/hibernate orm.

thanks

as per comment @jb nizet found spurious list in hierachy. solve need make sure using set. if have more 1 list jpa errors cannot fetch multiple bags. if have 1 list wont end duplicates


Comments