I get the warning "restkit.core_data:RKManagedObjectMappingOperationDataSource.m:264 Managed object cache returned 2 objects for the identifier configured for the 'MyEntity' entity, expected 1." only on my device, but never in the simulator.
The sqlite database in the simulator is fine, but on the device I have identical, duplicate entries. If I delete the database, the warning pops up again after a while. But only on the device.
I'm using Restkit 0.23.1 to import JSON data to core data with deleting orphaned objects. The identificationAttributes are set.
Any ideas, if there is a difference between the simulator and the device that may cause this problem?
Thanks for help.
EDIT
I get the error for various entities. This is my mapping for the entity ResellerType (I have only one mapping for each entity):
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"ResellerType"
inManagedObjectStore:[YPIDataProvider sharedDataProvider].objectManager.managedObjectStore];
[mapping addAttributeMappingsFromArray:@[ @"resellerTypeId",
@"resellerTypeName",
@"position" ]];
mapping.identificationAttributes = @[ @"resellerTypeId" ];
I have a To Manyrelationship to the Reseller table and a Many To Manyrelationship to my MetaData table.
This is my RestKit setup:
NSError *error = nil;
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:kDataModelName withExtension:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
self.managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
[self.managedObjectStore createPersistentStoreCoordinator];
[self.managedObjectStore
addSQLitePersistentStoreAtPath:self.pathToDatabase
fromSeedDatabaseAtPath:nil
withConfiguration:nil
options:@{ NSInferMappingModelAutomaticallyOption: @YES,
NSMigratePersistentStoresAutomaticallyOption: @YES }
error:&error];
[self.managedObjectStore createManagedObjectContexts];
// managedObjectCache: Configure a managed object cache to ensure we do not create duplicate objects:
NSManagedObjectContext *moc = self.managedObjectStore.persistentStoreManagedObjectContext;
self.managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc]
initWithManagedObjectContext:moc];
I delete the NSURLCache before I send a request to the server ([[NSURLCache sharedURLCache] removeAllCachedResponses]). Can you find anything wrong here?
Thanks for reading all this!
[_mapping setIdentificationAttributes:@[ @"objectId" ]];whereas objectId is you primary key on the core data object. - electronix384128