I have two entities: person and car. One person can have multiple cars. This should be a bidirectional relationship.
I'm wondering which entity should be the owner of relationship?
I made it like this, but somebody told me, he would do it in the opposite direction, because the goal is to ask person for information and a car is one of the information, which a person gives.
I found some information for manytomany relationship JPA: which side should be the owning side in a m:n relationship? but no for 1:n.
Person entity:
@JsonIgnore
@OneToMany(mappedBy = "person")
private Set<Car> cars = new HashSet<Car>();
Car entity:
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "person_car", joinColumns = @JoinColumn(name = "car_id"),
inverseJoinColumns = @JoinColumn(name = "person_id"))
private Person person;