I have 2 tables - Screenings (ManyToOne) and Rooms (OneToMany). When I'm using findAll on rooms repository it returns me a json with screenings data but when Im doing that in opposite way (screenings.findAll) it does not returns rooms. In model Screening I have relation:
@ManyToOne
@JoinColumn(name = "room_id")
@JsonBackReference
private Room room;
and in Room model:
@OneToMany(mappedBy="room")
@JsonManagedReference
private List<Screening> screenings;
ScreeningService contains:
@Autowired
public ScreeningService(ScreeningRepository screeningRepository) {
this.screeningRepository = screeningRepository;
}
public List<Screening> getScreenings(){
return screeningRepository.findAll();
}
and returned values are without Room model:
{
"id": 1,
"startDate": "2022-06-20T13:00:00.000+00:00",
"endDate": "2022-06-20T15:00:00.000+00:00"
},
{
"id": 2,
"startDate": "2022-06-20T13:15:00.000+00:00",
"endDate": "2022-06-20T15:15:00.000+00:00"
},
When Im doing that in opposite way and call
public List<Room> getRooms() {
return roomRepository.findAll();
}
result is exactly same as I want:
{
"id": 2,
"number": 2,
"screenings": [
{
"id": 2,
"startDate": "2022-06-20T13:15:00.000+00:00",
"endDate": "2022-06-20T15:15:00.000+00:00"
},
{
"id": 5,
"startDate": "2022-06-20T13:15:00.000+00:00",
"endDate": "2022-06-20T15:15:00.000+00:00"
},
{
"id": 7,
"startDate": "2022-06-20T18:15:00.000+00:00",
"endDate": "2022-06-20T21:15:00.000+00:00"
}
]
},
Is that possible to make or Im doing something wrong?