What if you don't set the many side of the following association? Does hibernate give an error? I read that its best to map the many to one side because it gives better performance, even if you dont need to be able to be able to get the owning object.
Also what if I have the mapping like below but I don't set the owner on the car object before adding it to the set of cars on the user side? will it make it so that you cant call .getCars() and get the newly adding object after persisting?
public class User { @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, mappedBy="user") Car getCars() { ... }
}
public class Car { @ManyToOne @JoinColumn(name="userId") User getOwner(){ ... } void setOwner(User user) { } }
|