I have three classes one of the names is User and this user has other classes instances. Like this;
public class User{
@OneToMany(fetch=FetchType.LAZY, ca
As I explained in this article and in my book, High-Performance Java Persistence, you should never use the unidirectional @OneToMany annotation because:
Now, in your first example, both sides are owning the association, and this is bad.
While the @JoinColumn would let the @OneToMany side in charge of the association, it's definitely not the best choice. Therefore, always use the mappedBy attribute on the @OneToMany side.
public class User{
@OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="user")
public List aPosts;
@OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="user")
public List bPosts;
}
public class BPost extends Post {
@ManyToOne(fetch=FetchType.LAZY)
public User user;
}
public class APost extends Post {
@ManyToOne(fetch=FetchType.LAZY)
public User user;
}