Hi Maik, thx for your detailed and quick answer! Ok the thing with the ChildContext was my fault, although I should know better, shame on me :-/ But anyway the result of my test is the same.
What I can verifiy is that when you commit sthg to a context, the child contexts gets synched immediatetly, when committing in childContext the change is also immediately visible in the parent context, but in other existing contexts. As I see my testcase was not very usefull ;-) regards Meex Musall, Maik <m...@selbstdenker.ag> schrieb am Do., 23. Feb. 2017 um 09:18 Uhr: > Hi Markus, > > > I'm having some troubles understanding commitChanges() and > > commitChangesToParent() :-/ > > > > I've created a test case with two ObjectContexts > > ObjectContext context1 = runtime.newContext(); > > ObjectContext context2 = runtime.newContext(); > > Those two don't have a parent/child relationship. For that you would have > to create context2 = runtime.newContext( context1 ); > > > then I load the same entity in both contexts > > PpAfkoPordershead order1 = PpAfkoPordershead.getByAufnr(context1, 123); > > PpAfkoPordershead order2 = PpAfkoPordershead.getByAufnr(context2, 123); > > > > then I tried this > > Integer quantity = order1.getQuantity(); > > order1.setQuantity(quantity + 1); > > context1.commitChanges(); > > Assert.assertEquals(quantity, order2.getQuantity()); > > > > this works as the second context get synched by the commit. > > Btw, this synchronization is on by default, and can be switched off. > Personally I can see the default changing some time in the future, because > in multithreaded applications this can lead to difficult runtime problems > when data that one thread is operating on changes mid-operation. For more > details, see this chapter in the Cayenne Guide: > https://cayenne.apache.org/docs/4.0/cayenne-guide/performance-tuning.html#turning-off-synchronization-of-objectcontexts > < > https://cayenne.apache.org/docs/4.0/cayenne-guide/performance-tuning.html#turning-off-synchronization-of-objectcontexts > > > > > > > but why does this work too? > > Integer quantity = order1.getQuantity(); > > order1.setQuantity(quantity + 1); > > context1.commitChangesToParent(); > > Assert.assertEquals(quantity, order2.getQuantity()); > > Works the same because the parent is the same, see answer part #1. But > that isn't what parent/child contexts are about anyway. The concept is more > like if context2 is a child of context1, you could commit something in > context2 to parent, and that would become visible in context1 as well, but > wouldn't hit the database until you also commit in context1. > > I'm fairly new to Cayenne as well, so if I got something wrong, I'm sure > someone will correct me. :-) > > Maik > >