if (object!=null && !(object.editingContext().parentObjectStore() instanceof EOObjectStoreCoordinator)) {
log.warn("Newly created object is in an editing context that will not save to the database");
}
localContext = ERXEC.newEditingContext(object.editingContext().parentObjectStore());
if (log.isDebugEnabled()) log.debug("Creating "+entityNameForNewInstances);
EOEnterpriseObject newEO = ERXEOControlUtilities.createAndInsertObject(localContext, entityNameForNewInstances);
// If the object already exists, then hookup the relationship, if not do it after the object is saved.
if (!((ERXEnterpriseObject)object).isNewObject()) {
EOEnterpriseObject localEO = EOUtilities.localInstanceOfObject(localContext, object);
if (localEO != null)
localEO.addObjectToBothSidesOfRelationshipWithKey(newEO, key);
}
if (preRelationshipKeys != null) {
for(Enumeration e = preRelationshipKeys.allKeys().objectEnumerator(); e.hasMoreElements();) {
String relationshipKey = (String)e.nextElement();
String objectKeyPath = (String)preRelationshipKeys.objectForKey(relationshipKey);
EOEnterpriseObject localObject = EOUtilities.localInstanceOfObject(localContext, (EOEnterpriseObject)object.valueForKeyPath(objectKeyPath));
localObject.addObjectToBothSidesOfRelationshipWithKey(newEO, relationshipKey);
}
}
localContext.hasChanges(); // Make sure the EC survives.
return newEO;
}