I have the following situation:
Classes:
Code:
class foo:
Set<Bar> bars;
class Bar:
Foo foo;
This is what I'm doing
Code:
Foo foo1 = somemethodThatChoosesFoo(ID);
Foo foo2 = somemethodThatChoosesFoo(ID);
Set<Bar> bars = foo1.getbars();
// now I'm picking some bar from the set bars
Bar bar = somemethodThatChoosesABar(bars, ID);
bar.setFoo(foo2);
dao.makePersistent(bar); // = session.saveOrUpdate(bar)
// Now displaying bars from foo1
for(bar : bars){
displayBar(bar);
}
What I want is: bar gets removed from "getBars()" from foo1 and gets added to "getBars()" from foo2.
What I get is: bar doesn't get removed from foo1 but is added to foo2. After a page reload (and transaction commit) the "getBars()" from foo1 is updated and I get the wanted behaviour.
Isn't it possible to update the "getBars()" from foo1 in memory first? (before committing the transaction)