Your mapping actually defines two independent unidirectional relationships. What you want is one bi-directional relationship. The following code will establish a bi-directional relation
@OneToMany(cascade = CascadeType.ALL, mappedBy = "purchaseListId") @JoinColumn(name="pl_id",referencedColumnName="id") private List<PurchaseListItems> purchaseListItems;
The mappedBy attribute is required because the provider cannot automatically determine that the specified relationship actually forms a single relationship. You can use the Java type of an instance member, but then if you have multiple members of the same type. And there are many scenarios where you have two separate relationships. Example:
OneToMany: User -> ForumThread (threads created by the user)
ManyToOne: ForumThread -> User (the user who closed the thread is obviously not necessarily the one who started the thread)
These are two independent relationships and should be considered as such. You would be surprised if your perseverance provided only a bi-directional connection from this only because the types and plurality were consistent.
Also note that bidirectional relationships are not automatically managed by any JPA provider, which means that the reverse side is not automatically updated / installed in your object model and therefore is not in db. You have to do it yourself. By the way, in all my projects, bidirectional relationships were a pain in the ass, and I think it is advisable to avoid them.
bennidi
source share