Код: Выделить всё
@Entity
@Table(name = "parent")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "Parent.all",
attributeNodes = {
@NamedAttributeNode(value = "child", subgraph = "Child.all"), // here I am referencing graph specified in Child entity
}
)
})
public class ParentModel {
@OneToOne(
mappedBy = "parent",
fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private ChildModel child;
}
< /code>
@Entity
@Table(name = "child")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "Child.all",
attributeNodes = {
@NamedAttributeNode(value = "grandChildren"),
}
)
})
public class ChildModel {
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private ParentModel parent;
@OneToMany(
mappedBy = "child",
fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set grandChildren;
}
< /code>
And I want to use the Spring Data repository method:
@EntityGraph(value = "Parent.all")
List
findAll();
< /code>
But I am still getting LazyInitializationException when I want to reference the grandChildrenПодробнее здесь: https://stackoverflow.com/questions/663 ... tity-graph
Мобильная версия