It depends on how these are mapped bi-directional and whether they are cached. The safest bet is to update all sides of the assocations you have defined to Hibernate. Typically this would mean something like:
Code:
A_B ab = new A_B();
ab.setA(a);
ab.setB(b);
a.getBs.add(ab);
b.getAs.add(ab);
or more succintly from client perspective:
Code:
A_B ab = new A_B(a, b);
// where :
public A_B(A a, B b) {
this.setA(a);
this.setB(b);
a.getBs.add(this);
b.getAs.add(this);
}
Quote:
- after saving the new instance of A_B, "manually" add A_B to the collection in A.
Specifically, this should be done
before saving the new instance of A_B...