0
My need was as follows: A report that would bring the Event and the number of hotel reservations that was associated with that Event. And so it followed as the code below shows:
List<IHotelReservation> iHotelReservationList = Lists.newArrayList();
iHotelReservationList.addAll(this.hotelReservationDao.listByReservationStatus(hotelReservationFilter));
iHotelReservationList.addAll(this.omnibeesHotelReservationDao.listByReservationStatus(hotelReservationFilter));
Map<Event, Integer> hotelReservationMap = Maps.newHashMap();
for (IHotelReservation iHotelReservation : iHotelReservationList) {
int hotelReservationQtd = 1;
if (hotelReservationMap.containsKey(iHotelReservation.getEvent())) {
hotelReservationQtd = hotelReservationMap.get(iHotelReservation.getEvent())+1;
}
hotelReservationMap.put(iHotelReservation.getEvent(), hotelReservationQtd);
}
this.result.include("hotelReservationMap", hotelReservationMap);
}
I still need to return a Map using Event as key. But now with the number of Allocations given that Event, no more Hotelreservations. It is worth mentioning that I have a List getAllocationList() in Ihotelreservation.
See if I understand: "1 Event has 1-N Hotelreservetion", and, "1 Event has 1-N Allocation", is that it? It would not be better to add to Event a Hotelreservetion List and an Allocation Client (note, if it is not possible or undesirable to change the Event class, you can create an "Eventholder" that would have 1 Event and the Hotelreservetion and Allocation Lists of that Event)?
– Douglas
Event has no Hotelreservation. 1-N Hotelreservation has 1 Event. 1-N Allocation has 1 Hotelreservation. There is a lot of resistance to changing the Event class.
– user63513
And what is the direct relationship between Event and Allocation? You simply want to add up the Allocations of all Hotelreservation that has a certain Event, doing this for each Event?
– Douglas
Exactly. The only relationship Allocation has with Event is Hotelreservation. I imagine you can go through the Hotelreservation list and pick up your Allocations.
– user63513
And what does "hotel_reservation_id" have to be? I couldn’t see yet why it would be necessary to implement this functionality.
– Douglas
It is. Now talking I realized that I don’t need it because before I was imagining that I would have to go through a list of Allocations and compare the hotel_reservation_id with the Hotelreservation id. Do you understand ? But I just need to go through the list of Hotelreservation Allocations.
– user63513
If you are already able to answer your question, answer it and accept the answer; otherwise you will need to edit your question: remove the business from the "hotel_reservation_id", show the "Ihotelreservation" method that returns the list of Allocations and tell what is type of return (is a List<Allocation>?). I imagine you want another Map<Event, Integer> evento_AllocationsAssociationsAoEvento , if that’s what triggers the question and explain what we talked about here in the comments.
– Douglas
I’m not able to answer my question yet and I edited it.
– user63513