Hi,
I have a question about initialization of reverse relations in one-to-many relations.
Example:
public class A {
Collection b;
public Collection getB() {
return b;
}
}
public class B {
A a;
public A getA() {
return a;
}
}
Now I add an instance of class B to an instance of class A:
A a=session.load((new A).getClass(),pkForA);
B b=session.load((new B).getClass(),pkForB);
a.getB().add(b);
Now I tried to get A from B:
b.getA();
It returns null!
I have to close the session (session.flush() is not enough), start a new one and load B again.
Then b.getA() returns the right object.
Can I force hibernate to set the reverse relation without using a new session?
|