Entity{
String code;
String parentCode;
...
@ManyToOne
@JoinColumn(name="parentCode",referencedColumnName="code")
Entity parentEntity;
}
我的实体类是这样的。我想要做的是使用 findAll() 获取实体列表,每个实体都有自己的直接父级。但是 spring jpa 将获取父级的父级直到 root ,我需要避免这种情况。 谢谢!
最佳答案
由于 @ManyToOne
关系的默认获取类型是 FetchType.EAGER
我认为您只需明确添加一个获取类型作为 LAZY
:
Entity{
String code;
String parentCode;
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="parentCode",referencedColumnName="code")
Entity parentEntity;
}
关于java - spring boot jpa ManyToOne(column ="fatherId")加入同一实体以递归方式工作,直到fatherId为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53080376/