I have a parent entity ParentClass. In this parent Entity I have a list of child classes as shown below:-
public class BaseClass{
@Id
private Long id;
}
@Entity
public class ParentClass extends BaseClass{
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<ChildClassA> childClassAList;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<ChildClassB> childClassBList;
}
In my database I only have one record for ChildClassA mapped to ParentClass(say my parent_class record has id 25001 and their is only one child mapped to this parent[from ChildClassA entity] say 45001) in my third table. But still when I am debugging parentClass.getchildClassAList(), It shows me 2 items in this list(and that too both with same ID) instead of one single record as shown below:-
ParentClass parentRecord = myDao.find(ParentClass.class,25001L); //shows only one record which is expected.
List<ChildClassA> allChildsOfParent = parentRecord.getchildClassAList(); //shows 2 items in list,each with same id 45001 even though the third table in db carries one single record corresponding to this parent with id 25001.
What could be the possible reason for this issue? Any help would be appreciated.