• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in EJB store  RSS feed

Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have 1-M CMr relationship
PA(table)1 - M ContractLimits(table)
Now, there is a save(Collection collectionOfContractLimitsValueObjects) method written in a session bean which does something like this
loop on the collection of value objects
do find by PK on the ID
set the new values on the bean
Now all this runs fine for single user but fails giving deadlock on multiple users.I can't understand why there is a deadlock for this situation

Here is the stacktrace
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/SUN] SQL0911N The current transaction has been rolled back because of a deadlock or timeout. Reason code "2". SQLSTATE=40001
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.net.DB2PreparedStatement.executeUpdate(Unknown Source)
at weblogic.jdbc.jts.Statement.executeUpdate(Statement.java:509)
at weblogic.jdbc.rmi.internal.PreparedStatementImpl.executeUpdate(PreparedStatementImpl.java:82)
at weblogic.jdbc.rmi.SerialPreparedStatement.executeUpdate(SerialPreparedStatement.java:58)
at com.circuitcity.vma.ejb.pa.local.PAContractLimitsEntityBean_dgbmrd__WebLogic_CMP_RDBMS.__WL_store(PAContractLimitsEntityBean_dgbmrd__WebLogic_CMP_RDBMS.java:2295)
at com.circuitcity.vma.ejb.pa.local.PAContractLimitsEntityBean_dgbmrd__WebLogic_CMP_RDBMS.ejbStore(PAContractLimitsEntityBean_dgbmrd__WebLogic_CMP_RDBMS.java:2121)
at weblogic.ejb20.manager.DBManager.storeBean(DBManager.java:467)
at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:615)
at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:633)
at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:540)
at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:92)
at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1060)
at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1597)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:237)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
at weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
at com.circuitcity.vma.ejb.pa.facade.PASessionFacade_ywcnz3_EOImpl.save(PASessionFacade_ywcnz3_EOImpl.java:110)
at com.circuitcity.vma.web.manager.PAManagerBD.save(PAManagerBD.java:1498)
Can anybody help me here?
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Monmohan,
It could be that when multiple users saving ContractLimits they saving same limits in a different order.
Eg, user1 needs to save ContractLimit1/ContractLimit2 and user needs to save ContractLimit2/ContractLimit1 at the same time. On the database end side user1 locks ContractLimit1 record and user2 locks ContractLimit2 record. Then user1 needs a lock on ContractLimit2 record (which is currently held by user2) and user2 needs a lock on ContractLimit1 record (which is currently held by user1). This situation will result in the database deadlock
One way to avoid such deadlock is to access objects in the same order. You could use java.util.List interface as the type of the parameter in your save() method. Then on the caller side you'd populate this list with the ContractLimit objects in some ordered fashion (i.e. two instances of this list would have two same ContractLimit objects appearing in the same order - if list1 has ContractLimit1 followed by ContractLimit2 then list2 has ContractLimit1 followed by ContractLimit2).
If that was the case then in our scenario user1 would be first saving ContractLimit1 and then ContractLimit2; and user2 would be first saving ContractLimit1 and then ContractLimit2. User1 locks ContractLimit1 record - user2 needs this lock and waits for user1 to release it; user1 unlocks ContractLimit1 record - user2 acquires lock on ContractLimit1 record and so on.
Hope it helps.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!