Re: in another EC, when objects transferred through GIDs, owning relationship does not delete objects?!?
Re: in another EC, when objects transferred through GIDs, owning relationship does not delete objects?!?
- Subject: Re: in another EC, when objects transferred through GIDs, owning relationship does not delete objects?!?
- From: OC <email@hidden>
- Date: Thu, 26 Feb 2015 09:25:53 +0100
Ken,
On 26. 2. 2015, at 5:14, Ken Anderson <email@hidden> wrote:
> First, why are you expecting the object to be deleted when you just remove it from the relationship?
For it is an owning relationship (and it does work all right in the first case). I might be missing some important point here, but I've always thought that is sort of the very purpose of owning relationships?
> Second, have you removed calls to lock() and unlock(), or are you not calling them?
I am not. Again I might be missing something, but I understand ERXEC does autolock -- even in a background thread -- as needed, albeit possibly not in the most efficient manner (e.g., http://lists.apple.com/archives/Webobjects-dev/2007/May/msg00578.html).
(Besides frankly, I don't really see the need to lock an EC at all, given the EC is created, used and released in one separate thread and never shared anyhow with other threads; but then, superfluous locking does not harm anything but efficiency, and efficiency is not paramount with background threads.)
Thanks and all the best,
OC
>> On Feb 25, 2015, at 7:07 PM, OC <email@hidden> wrote:
>>
>> Hello there,
>>
>> I've bumped into rather a weird (at least to me) behaviour. Is this normal and am I just overlooking something by expecting it to work?
>>
>> I've noticed lately that my background tasks (each of which uses its own EC) stopped to delete old objects. Pursuing the culprit, I have found that it began when I (by Ramsey's advice) stopped moving objects betwixt those ECs using localInstanceIn, replacing it by explicit globalID-based creation (only, by Chuck's advice, I am using faultForGlobalID instead of ERXEOGlobalIDUtilities.fetchObjectWithGlobalID).
>>
>> I am able to repeat the problem e.g., this way:
>>
>> === launched very early in Application, no session/component created yet ===
>> def ec=ERXEC.newEditingContext()
>> def auction=EOUtilities.objectWithPrimaryKeyValue(ec,'DBAuction',1000003)
>> def records=auction.importedRecords()
>> println "owning rel: ${auction.ownsDestinationObjectsForRelationshipKey('importedRecords')} inverse '${auction.inverseForRelationshipKey('importedRecords')}' #$records.count" // just to make sure it's all right
>> def lr=records.lastObject()
>> println "-- in 'default' EC removing $lr from $auction..."
>> lr.removeObjectFromBothSidesOfRelationshipWithKey(auction,'auction')
>> auction.editingContext().saveChanges() // my delegate logs out all adaptor ops: this does delete all right
>>
>> def ec2=ERXEC.newEditingContext(new EOObjectStoreCoordinator())
>> auction=ec2.faultForGlobalID(auction.permanentGlobalID(),ec2) // this is how I 'move' objects to background tasks...
>> lr=ec2.faultForGlobalID(records.lastObject().permanentGlobalID(),ec2) // ... is it indeed the right way?
>> println "-- in EC in extra OSC removing $lr from $auction..."
>> lr.removeObjectFromBothSidesOfRelationshipWithKey(auction,'auction')
>> auction.editingContext().saveChanges() // for this one DOES NOT delete, see the logs below!
>> ===
>>
>> This code -- along with the logs in databaseContextWillPerformAdaptorOperations -- prints out this:
>>
>> ===
>> owning rel: true inverse 'auction' #2
>> -- in 'default' EC removing <DBRecord@1532707037 PK:1004656 /EC:829232957> from <DBAuction@357286753 PK:1000003 /EC:829232957>...
>> - 1: DELETE on 'DBRecord' (uid = 1004656)
>> -- in EC in extra OSC removing <DBRecord@2038388710 PK:1004657 /EC:489384291> from <DBAuction@325329592 PK:1000003 /EC:489384291>...
>> - 1: UPDATE on 'DBRecord' (uid = 1004657) 1{auction_id:<com.webobjects.foundation.NSKeyValueCoding$Null>}
>> ===
>>
>> Does it make any sense?
>>
>> Note: if I replace the 'lr.removeObjectFromBothSidesOfRelationshipWithKey' by ec2.deleteObject(lr), it works all right, deleting the record in both cases.
>>
>> Thanks,
>> OC
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden