I am trying to add a list of rented books to my database.
I am using ModelMaper with SpringBoot.
Here is code:
RentDto.java
@Getter
@Setter
@EqualsAndHashCode
@ToString
@NoArgsConstructor
public class RentDto {
private Long rentId;
private Long userId;
private Long bookId;
private String userFirstName;
private String userLastName;
private String bookTitle;
private LocalDateTime rentStart;
private LocalDateTime RentEnd;
}
RentController.java
@ApiOperation(value = "Add Multiple Rents")
@PostMapping("/addMultipleRent")
@ResponseStatus(HttpStatus.CREATED)
public void addMultipleRent(@RequestBody List<RentDto> rentDto){
rentService.addMultipleRents(rentDto);
}
RentService.java
public void addMultipleRents(List<RentDto> rentDto){
rentRepository.saveAll(mapRentListDtoToRentList(rentDto));
}
//Convert List of books to List of bookDto
private List<Rent> mapRentListDtoToRentList(List<RentDto> rents) {
return rents.stream()
.map(rent -> modelMapper.map(rent, Rent.class))
.collect(Collectors.toList());
}
I am getting the following error:
1) The destination property com.example.library.entity.Rent.setId() matches multiple source property hierarchies:
com.example.library.dto.RentDto.getRentId()
com.example.library.dto.RentDto.getUserId()
com.example.library.dto.RentDto.getBookId()
Any help appreciated.