There are only one generic solution to avoiding your deadlock. Do all your updates in the same order (A then B) in all threads.
Are you using row locking? If not, us it. If you are, you might look at why you have so many concurrent updates of the same rows. Either change your UI design or data model to avoid high contention.
--Victor
Janne Mattila wrote:
Hi,
I'm developing some BMP entity beans with WebLogic 6.1 & Oracle 9 and am running into lots of ORA-00060 deadlock detected errors. I know the cause of this, but seem to have a chicken and egg situation when trying to solve this...
Let's say we have two entity beans, A and B, with 1:1 relationship between them. Both have accessor methods to each other
A.getB() B.getA()
in database one of the tables hold foreign key pointing to another's primary key. It's not important which one.
Now, we have an application where you can view & edit both entities. View screen for A shows also B and vice versa. Pseudo-code for these view screens would be:
view A:
aToShow = findByPrimaryKey(primary_key_from_user) bToShow = a.getB()
view B:
bToShow = findByPrimaryKey(primary_key_from_user) aToShow = b.getA()
Now, the problem is that WebLogic seems to call ejbStore() in the order in which the beans were initially accessed. Let's say thread #1 views A and thread #2 views corresponding B. This would create following SQL:
thread #1: UPDATE A SET...WHERE ID = 203 thread #2: UPDATE B SET...WHERE ID = 17 thread #1: UPDATE B SET...WHERE ID = 17 (waits for lock by #2) thread #2: UPDATE A SET...WHERE ID = 203 (waits for lock by #1 => deadlock)
Now, there could be some "hacks" around this, but the situation is not this simple since this occurs in much more complex situations and where data is actually updated. Maybe in this case some ejbSelect -methods could be used to reverse the order in one of the views, but this is really not practical when cases get more complex. Is there any generic way to avoid such problems while still using BMP and same data model?
Interestingly enough, I do not seem to get the same problem with CMP & CMR. I wonder why this is the case. Still I would need to get BMP also working.
- - - Janne Mattila
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".