In a JPA 2.0 application, a dual JOIN FETCH statement returns incorrect results when one of the properties is a list with FetchType.LAZY; the list property has all records duplicated after execution of the query: SELECT p FROM test_parent p JOIN FETCH p.children1 JOIN FETCH p.children2
Here we have one parent entity class and two child entity classes, associated via @OneToMany relationships from the parent class. The parent is tied to one child class via a Map, and to the other via a List. Both collection properties are FetchType.LAZY:
public class Parent { @Id @Column(name = "parentId", unique = true, nullable = false) public int id;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "parent") @MapKey(name = "myval") public Map<Integer, Child1> children1 = new HashMap<>();
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "parent") public List<Child2> children2 = new ArrayList<>(); }
I created a JIRA defect for this defect (HHH-7895), but was asked to post to the forum first. A full test case that includes the child classes is attached to the defect.
Comments appreciated.
Thanks,
Uli
|