Recovering from deadlock (Re: duplicate pk error: recovering from)
David Deininger <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <BA3F0BC6.9421%[email protected]> |
Then how about a related question, one which has me stumped at present.
How do I recover from a database deadlock during commit?
The deadlock occurs because we have multiple applications inserting data
simultaneously, and sometimes (very rarely, but it happens) two apps will
attempt to insert the same record (same PK) at the same time.
We can catch the exception and check the userInfo to see that it's a
deadlock, but doing the naïve thing and calling saveChanges() again doesn't
appear to work as expected.
Has anyone done this sort of thing (successfully) already? We're using an
Oracle database, in case it matters.
--david
On 1/3/03 2:03 PM, "Chuck Hill" <[email protected]> wrote:
> A better question might be, "Why am I getting this duplicate PK error?" It
> seems to me that it would be better to avoid this than to recover from it.
> The only time I've seen this happen is with a M-M join table with a complex
> PK on the two FKs. I don't know that this is your problem but assuming it
> is...
>
> In this situation if you remove one of the joins (using
> removeObjectFrom...) and then replace it with an equivalent one (using
> addObjectTo...). The real problem here is that EOF does not order the
> operations correctly, issuing the inserts before the deletes.
>
> I don't think you can defer the unique constraint checking on a PK, so some
> possible solutions are:
> 1. Order the database operations yourself
> 2. Add a generated PK to the join table as a third column
> 3. Change your code so that you never remove a join and then add an
> equivalent. This makes working with WOBrowser etc a tad more challenging.
>
> You will probably find 2 to be the least time consuming.
>
>
> Chuck
>
> At 11:47 AM 03/01/2003 -0600, Jonathan Rochkind wrote:
>> Let's say I know I'm about to perform an insert to the db which might
>> result in a "cannot insert duplicate pk" excpetion. I want to CATCH this
>> exception, and then RECOVER from it. That is, restore the EOF stack so it's
>> not trying to insert that bad EO anymore, it just gets rid of the bad EO.
>>
>> I can't quite figure out how to catch that exception, nor can I figure out
>> how to recover from it. At the moment, once that exception occurs, my
>> EOEditingContext is permanently polluted. Every time I try to saveChanges
>> on that EC again, it will again try to insert the duplicate pk, and again
>> get the exception.
>>
>> Anyone have any hints?
>>
>> --Jonathan
>>
>> _______________________________________________
>> EOF mailing list
>> [email protected]
>> http://www.omnigroup.com/mailman/listinfo/eof
>>
> _______________________________________________
> EOF mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/eof
>