vifeng / TicketToTheMoon

WIP: Ticket office website. back office for venues to operate their shows and front office to buy tickets for the public.
1 stars 0 forks source link

Lazy loading of Booking entity #25

Closed vifeng closed 7 months ago

vifeng commented 8 months ago

Steps to reproduce the bug

get request : localhost:8080/api/bookings

Error

"timestamp" : "12-03-2024 16:33:25",
"statusCode" : 400,
"path" : "/api/bookings",
"message" : "A generic error occurred : Could not write JSON: failed to lazily initialize a collection of role: 
com.vf.eventhubserver.domain.model.Venue.employees: could not initialize proxy - no Session"

Trace

.m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON:
 failed to lazily initialize a collection of role: com.vf.eventhubserver.domain.model.Venue.employees: could not initialize proxy 
- no Session]

Expected behavior

should return employee of the venue.

Proposed solution

  1. add fetch = FetchType.EAGER in venue entity
  2. write a new DTO which exclude employees
  3. @Transactional in services. Already done.
vifeng commented 8 months ago

I should opt for add fetch = FetchType.EAGER in venue entity as it is a demo project with few data. Depending on the client and functional requirements I should write different DTO/mapper to return different values. Booking should only return the bookings of the current user. It will be implemented with the security.