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.