RE: Core data save error with multiple persistent stores
RE: Core data save error with multiple persistent stores
- Subject: RE: Core data save error with multiple persistent stores
- From: Arthur C. <email@hidden>
- Date: Sun, 16 Nov 2008 22:30:08 +0100
- Importance: Normal
From: email@hidden: email@hiddenbject: Core data save error with multiple persistent storesDate: Sun, 16 Nov 2008 21:02:37 +0100
In my application I have two managed object contexts, as I need to be able to save two subsets of my Core Data setup separately. These are both using one and the same persistent store coordinator; the coordinator has two stores. I take care that every object instance gets inserted into the right managedObjectContext, by using [NSEntityDescription insertNewObjectForEntityForName: ...]. And it gets assigned to the right persistent store by using - (void) awakeFromInsert{ ... [managedObjectContext assignObject:self toPersistentStore: [persistentStoreCoordinator persistentStoreForURL: url]];}.There are no relationships between objects in different persistent stores, as it should be. This seems to work OK on one system, but leads to a strange error on two other systems (for the same program). When a change has been made to the Core Data objects (e.g. adding an instance), the 'save' action of the managedObjectContext gives an exception (no error screen) saying 'can't reassign object to a different store once it has been saved'. This means the Core Data stack cannot be saved anymore, which is of course a serious problem. Do you know what causes this error? Do I need to use a different setup for the managedObjectContext - persistentStoreCoordinator - persistentStores system? Thanks for your time,Arthur C.
> The example in the documentation:> http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdCreateMOs.html#/ >/apple_ref/doc/uid/TP40001654-SW2>>does the assignment immediately after the >"insertNewObjectForEntityForName" call, not in "awakeFromInsert".
All right, but that does not cover the case of an object being added using the 'add' button linked to the array controller (which btw is bound to the correct managedObjectContext). Then you end up directly in awakeFromInsert, which at least should be OK if it is executed only once.
>I'm wondering if undo is what's causing your problem. If not undo, >then some other circumstances that leads to "awakeFromInsert" being >called when the object is not really brand-new.
I'll check that. Undo is probably not the problem, we can trigger the error without doing an undo operation.
>Have you tried doing it the way Apple's example shows?
I'll do that, but as said, it's incomplete and the awakeFromInsert will still be needed...
Thanks so far,
Arthur C.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden