I made this minimal example to help visualize the relation I want to implement:
AFAIK in Spring Boot I need to configure:
On Car:
@ManyToMany
@JoinTable(
name = "cars_tags",
joinColumns = @JoinColumn(name = "car_id"),
inverseJoinColumns = @JoinColumn(name = "tag_id")
)
private Set<Tags> tags= new HashSet<>();
And on Tag:
@ManyToMany(mappedBy = "tags")
private Set<Car> cars = new HashSet<>();
However, I'm also utilizing DTOs, so when creating a car, the REST body needs to have a CarRequestDTO:
private String model
private String year
private Set<String> tagIds;
Finally, I'd save on the @Service class, using the Car repository, with:
// validating DTO
validateCar(carRequestDTO);
// convert CarRequestDTO to Car and copying properties
Car car = new Car();
BeanUtils.copyProperties(carRequestDTO, car);
// save
carRepository.save(car);
However, when saving, the table cars_tags retains no data at all. I'd like to know what I could possibly doing wrong (or not doing at all).
Thank you for the help.