我的两个实体之间有@ManyToMany 关系。当我尝试将父母与他们的孩子一起加载时,父母会重复响应有效载荷。我想解决我的问题EntityGraphs
。
这是带有注释的父级。
@Entity
@Table(name="Parent_table")
@NamedEntityGraph(
name = "Parent.children",
attributeNodes = @NamedAttributeNode("children"))
public class Parent implements Serializable{
//some extra code
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
name="join table", joinColumns=@JoinColumn(name="key"),inverseJoinColumns=@JoinColumn(name="key"))
private List<Child> children;
这是父存储库中的代码。
@EntityGraph(value = "Parent.children", type = EntityGraphType.LOAD)
public List<Parent> findAll(Predicate predicate);
我的两个实体之间有多对多的关系。但我想得到像
parent1 {
child1,
child2
}
但是我为每个组合都得到了父母..
Parent1 {
child1,
child2
}
Parent1 {
child1,
child2
}
在那里我得到了parent2。
但我想要的是只获得一次 parent1 ,而不是重复。使用实体图时。