I'm learning Hibernate and faced a question: what is the difference between mappedBy
and CascadeType.ALL
?
We use mappedBy
on the owning side in order to eliminate excessive persistence. For instance, with mappedBy
we can replace
a.addB(b);
b.setA(a);
with
a.addB(b);
in a case of ONE-TO-MANY relationship between A and B, and MANY-TO-ONE between B and A (bidirectional).
Why do we need CascadeType
in this case?