春季JPA提取嵌套实体
我有3个具有关系的实体课程:
class SocietyData {
@OneToMany(mappedBy = "societyData")
private List<SubsectionData> subsectionDataList = new ArrayList<>();
}
class SubsectionData {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "society_id", nullable = false)
private SocietyData societyData;
@OneToMany(mappedBy = "subsectionData")
private List<BasementData> basementDataList = new ArrayList<>();
}
class BasementData {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "subsection_id", nullable = false)
private SubsectionData subsectionData;
}
我试图使用实体图来获取社会数据信息:
@Repository
public interface SocietyRepo extends JpaRepository<SocietyData, Long> {
@EntityGraph(attributePaths = {"subsectionDataList", "subsectionDataList.basementDataList"})
Optional<SocietyData> findById(long id);
}
我没有得到适当的社会数据对象,并且有时花了这么长时间之后,我就不会得到无法解析的JSON例外!
如何解决这个问题?
提前致谢。
I have 3 entity classes with relations as below:
class SocietyData {
@OneToMany(mappedBy = "societyData")
private List<SubsectionData> subsectionDataList = new ArrayList<>();
}
class SubsectionData {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "society_id", nullable = false)
private SocietyData societyData;
@OneToMany(mappedBy = "subsectionData")
private List<BasementData> basementDataList = new ArrayList<>();
}
class BasementData {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "subsection_id", nullable = false)
private SubsectionData subsectionData;
}
I am trying to fetch society data information by using entity graph:
@Repository
public interface SocietyRepo extends JpaRepository<SocietyData, Long> {
@EntityGraph(attributePaths = {"subsectionDataList", "subsectionDataList.basementDataList"})
Optional<SocietyData> findById(long id);
}
I am not getting proper society data object and getting cant parse json exception after taking so long time sometimes!
How to solve this?
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论