I ran into a problem when data is recursively replicated. I wanted the child to not receive parental data. This causes a recursive problem. I mentioned the code below
Pojo Structure
class Parent {
..
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
private List<Child> childs;
..
}
class Child {
..
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentId")
private Parent parent;
..
}
Getting data like this
` em = EMF.get().createEntityManager();
Query q = em.createQuery("Select p from Parent p", Parent.class);
List<Parent> parents = q.getResultList();
parent.getChilds();
`
It retrieves data as follows:
Parent
child1
Parent
child2
Parent
child2
Parent
..
..
child2
..
What I don't need, I just need data like this:
Parent1
child1
child2
Parent2
child1
child2
child3
Ashk source
share