데이터가 재귀 적으로 발생하는 문제가 있습니다. 아이가 부모 데이터를 가져 오지 않도록하고 싶었습니다. 어떤 재귀 문제가 발생합니다. 내가 그나마부모 - JPA 가져 오기를 건너 뛰기
Parent
child1
Parent
child2
Parent
child2
Parent
..
..
child2
..
: 나는이
` em = EMF.get().createEntityManager();
Query q = em.createQuery("Select p from Parent p", Parent.class);
List<Parent> parents = q.getResultList();
// Till this point all looks good but when the code gets executed
parent.getChilds();
`
그것은이 같은 데이터를 가져 오는 것처럼 데이터를 가져 오기
뽀조 구조
class Parent {
..
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
private List<Child> childs;
..
}
class Child {
..
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentId")
private Parent parent;
..
}
아래의 코드를 언급 한 필요한 데이터는 다음과 같습니다.
FetchType.EAGER
동안
Parent1
child1
child2
Parent2
child1
child2
child3
기본적으로 기본 가져 오기 모드는 기본적으로 느슨한 – soorapadman
입니다. @soorapadman은 대다수의 경우 페치가 지연되고 일대일 관계가 열망하는 경우 – crizzis
어떤 공급 업체입니까? OneToOne/ManyToOne의 Lazy 페칭은 공급자에 따라 다르며 환경에 따라 더 많은 것을 요구할 수 있습니다. 예를 들어, EclipseLink는 weaving을 요구합니다. https://www.eclipse.org/eclipselink/documentation/2.5/concepts/app_dev007.htm – Chris