admin管理员组文章数量:1355540
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.
本文标签: databaseHow to configure a N11N SQL relation on SpringBoot while also using DTOsStack Overflow
版权声明:本文标题:database - How to configure a N:1:1:N SQL relation on SpringBoot while also using DTOs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744017771a2576650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论