Home > Enterprise >  The method save(S) in the type CrudRepository<TourClaimModel,Integer> is not applicable for th
The method save(S) in the type CrudRepository<TourClaimModel,Integer> is not applicable for th

Time:11-30

I am unable to understand why am not able to use save method in controller. I am using spring boot version 2.2.6. When is use this method it showing this error "The method save(S) in the type CrudRepository<TourClaimModel,Integer> is not applicable for the arguments (List)"

Here is my code,

@RequestMapping(method = RequestMethod.POST, value = "/tourClaim")
public String tourClaimApprovedByYuv(@RequestBody ArrayList<Integer> claimidList, Principal p) {
  String result = "";
  List<TourClaimModel> tour = tourClaimRepository.findByIdIn(claimidList);
  tourClaimRepository.save(tour);
  result = "Success";

  return result;
}

how can I resolve this?

CodePudding user response:

Just iterate over the list of TourClaimModel and save each one of them:

@RequestMapping(method = RequestMethod.POST, value = "/tourClaim")
public String tourClaimApprovedByYuv(@RequestBody ArrayList<Integer> claimidList, Principal p) {
    String result = "";
    List<TourClaimModel> tours = tourClaimRepository.findByIdIn(claimidList);
    for (TourClaimModel tour : tours) {
      tourClaimRepository.save(tour);
    }
    result = "Success";

    return result;
}

However, I don't get what you are trying to achieve since you are saving the objects you just retrieved from the database without any change.

CodePudding user response:

CrudRepository#save is used for persisting one entity.
If you want to save many, you need to use saveAll

@RequestMapping(method = RequestMethod.POST, value = "/tourClaim")
public String tourClaimApprovedByYuv(@RequestBody ArrayList<Integer> claimidList, Principal p) {
  String result = "";
  List<TourClaimModel> tour = tourClaimRepository.findByIdIn(claimidList);
  tourClaimRepository.saveAll(tour);
  result = "Success";

  return result;
}
  • Related