Hi,

On 2014-11-25, 2:15 PM, "OC" wrote:

Chuck,

===
  ... code as above ...
  if (ocs_is_primary_key_constraint(exception) && 
adaptorOp.adaptorOperator()==EODatabaseOperation.AdaptorInsertOperator) {
    NSArray pka=entity.primaryKeyAttributes()
    EOQualifier 
pkq=ERXEOAccessUtilities.qualifierFromAttributes(pka,adaptorOp.changedValues()) 
// contains the PK
    EOFetchSpecification fs=new EOFetchSpecification(entityName,pkq,null)
    fs.setRefreshesRefetchedObjects(YES)
    NSArray objs=ec.objectsWithFetchSpecification(fs)
    if (objs.count()==1) {
      // OK, my code does get here, the object inserted by other instance is 
fetched all right. But what now?!?
      ???
      _saveTolerantlyChangesInEC(ec) // let's try again
    ... ...
===

Set the relationships for any other objects into the EC to the one fetched, not 
the one just created and then ec.deleteObject(dupicate object))

Hmmm, there's one weird thing -- sometimes, I get from  
ec.objectsWithFetchSpecification the VERY SAME object which is in 
ec.insertedObjects?!?

Interesting.  I think your setting of the PK is confusing EOF as it identifies 
objects with a combination of Entity and PK.  So you have one EO in memory 
marked as "new, to be saved" and another one that has been fetched and is 
obviously not new.  I will assume that changing to not use a PK that you define 
is not an option at this point in time.



I've tried to add

            ec.fetchTimestamp=System.currentTimeMillis()

but it does not seem to help, still I keep getting the same object in the 
insertedObjects array AND fetched. If this happens, I am sorta SOL, for

(a) if I do not delete the object, it gets inserted again, and the exception 
repeats
(b) if I do delete it, not much surprisingly I'm in for a "cannot save changes: 
Cannot obtain globalId for an object which is not registered in any 
editingContext".

What if you do this when the exception arises:

  1.  Set relationships to this EO to null
  2.  Delete the object to get it out of inserted objects
  3.  Fetch the object
  4.  Set the relationships to the fetched object
  5.  Save again


Now I am investigating what might be the culprit (so far in vain). If you can 
see a possible reason -- or at least a solution, let me please know.

The EOGlobalID is the same but the inserted state is captured in the EC.  How 
hard would it be to re-create the whole set of objects to be saved in a 
different EC?


Chuck

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to