Transaction RolledBack Due to deadlocks


EJB programming & troubleshooting: Transaction RolledBack Due to deadlocks

  1. Transaction RolledBack Due to deadlocks (6 messages)

    Hi Everyone,
                   I have the scenario like a session bean S accessing two entity beans A and B If more than one users accessing the same session bean then "Transaction Rollback due to deadlock" exception is occuring.I have used transaction as "required" for all the beans.Can any body give solution for this.Server i m using is weblogic5.1.0.

    Thanx in advance


  2. Weblogic 5.1 uses Pessimistic locking, so once the object is in a transaction it is locked until the transaction is complete. Even if another bean needs read only access. The locking is also happening within the Weblogic container and not the database, which is more of a problem. Weblogic fixed this problem with Weblogic 6.0 which uses optomistic locking. The server can defer the locking to the database, which in my opinion is much better(especially if you are using a database like Oracle). It works much better. As I see it, you have several options. 1) Upgrade to Weblogic 6.0. 2) Use a third-party tool like Top Link, 3) or redesign you app to avoid locking problems.

    Good luck,

  3. I don't think you are having a pesimistic locking problem, you are getting a "deadlock" not a timeout error. Do you have some code in say entity bean B that access entity bean A? or in your session bean do you wait for results from entity bean b and update entity bean a?

    Deadlocks happens when session 1 is waiting for session 2 to free up entity a and session 2 is waiting for session 1 to free up entity b. Since they both will just wait for ever the container picks the one that started last and kills it. I am guessing you get entity a do something, release it, get entity b do something and update entity a again, but in that amount of time session 2 already has entity a and is waiting for session 1 to get done with entity b.

  4. Rich makes a good point about whether entity bean A is calling entity bean B. Not recommended in case you may have some rentry issues. It is good practice to handle the relationship of entity beans with a session bean. Using Entity beans can be tricky, because there are methods like EJBLoad and EJBStore that fire off without your knowledge. The container determines when those methods should fire. Thats why I prefer to handle data from a database in a stateless session bean. You do a findby on a bean, you lock the bean. You do a get or set, your are probably going to lock the bean. Do you have a sequence diagram so you can get a good feel for what your transactions are doing? This would be a good starting point to figure out what is going on.


  5. Hi Rich/kent

          Thanx for ur response.u r right. I m using two entities in a method of session bean.First data has to be updated in Entity 1 then entity 2 will be updated.For that could u give better solutions.Again thanx a lot to both of u.
  6. Are you updating both entities from the session, or are updating one entity, and that entity is updating another entity?

  7. Hi Kent,

            i m updating both the entities simultaneously.Niether entity calls other entity.Its a scenorio like i have to get the information from both the table which r related one to one.First i get the information from child table by using entity say A and Using the foreign key i retieve the information from parent table.All these things happening in a perticular method of session bean.The problem arises when more than one record has to be retrieved.Hope u get the things clearly.