I started coding a backend for a web app with Spring Boot. I have two classes; the first is 'User,' and the second is 'Equipment.' Now, for the 'User,' it has a list of equipments called 'ownedEquipments':
@OneToMany(mappedBy = "currentUser" , fetch = FetchType.LAZY , cascade = CascadeType.ALL)
private List<Equipment> ownedEquipments = new ArrayList<>();
And for the 'Equipment,' it has an attribute called 'currentUser,' representing the user that owns the equipment:
@ManyToOne(cascade = CascadeType.ALL)
private User currentUser;
The problem now is that when I try to fetch a user that has some equipments, it creates in the response object a loop of users inside equipment inside user. Does anyone have any idea?
And here is the link to the project on GitHub if someone needs to see the whole code: https://github.com/AdibChiguer/EquipPro-PFE
I want to fetch the user with their owned equipment without using a loop. Similarly, when I fetch the equipment, I also want to include the user field without using a loop. I tried using the ignore annotation, but in some cases, I still want to retrieve the fields that I ignored.