Reputation: 103
I have customers and books in my table. When a customer is deleted I also want book's availability to be set to available. When I only execute the code without first 3 lines of the method(setting availability to the available) it works perfectly fine and deletes the customer object. But when I add those lines to set books available then nothing happens and customer object stays without any removal.
@GetMapping("/customers/delete/{id}")
public String deleteCustomer(@PathVariable("id") int theId, Model model){
Customer c1 = CustomerService.getSingleCustomer(theId).get();
for(int i=0;i<c1.getRentedBooks().size();i++){
c1.getRentedBooks().get(i).availability="Available";
}
CustomerService.delete(theId);
return "redirect:/customer/listofcustomers";
}
Upvotes: 1
Views: 297
Reputation: 285
If field availability in Book class is private, use:
c1.getRentedBooks().get(i).setAvailability("Available");
Upvotes: 1