Hi all,
I have recently bumped into a problem with using nested editing contexts to accomplish add/edit workflows. What I'm doing seems simple enough, and correct from my understanding of the documentation. I'm creating a nested editing context:
EOEditingContext nestedEC = new EOEditingContext(session.defaultEditingContext);
and then creating my EOs in this. When it's time to save, I do the following:
nestedEC.saveChanges(); session.defaultEditingContext().saveChanges();
This seems to work fine with newly created items. The problem comes when I try to do that on an item that has been modified. I have printed out a few things within the code to confirm this: when the nested editing context saves its changes, it's supposed to push them into its parent context (or so I thought), but this is definitely not happening. Is this a well known issue? Has anyone seen this before? Am I missing something? A couple of hours of googling turned up nothing for me. The code and its output is shown below.
Thanks in advance for any help.
NSLog.out.appendln("nestedEC updatedObjects: " + nestedEC.updatedObjects()); NSLog.out.appendln("nestedEC.parent: " + nestedEC.parentObjectStore()); NSLog.out.appendln("session.defaultEditingContext: " + session.defaultEditingContext()); nestedEC.saveChanges(); NSLog.out.appendln("session.defaultEditingContext updatedObjects: " + session.defaultEditingContext().updatedObjects()); session.defaultEditingContext().saveChanges();
The output is:
nestedEC updatedObjects: (Test, 380.00, null) nestedEC.parent: er.extensions.ERXEC@ad81d2 session.defaultEditingContext: er.extensions.ERXEC@ad81d2 session.defaultEditingContext updatedObjects: ()
The first line shows that there is an updated object in the nested EC The second and third lines show that the ec is actually nested within another editing context and that the nested ec's parent is the session's default editingContext The fourth line shows that after calling saveChanges() in the nested ec, the parent ec still is showing no objects to update
Consequently, if I check the database after calling the final saveChanges, my change is not there. |