0 Replies Latest reply on Mar 31, 2004 7:49 AM by finn

    Questions about transaction rollbacks

    finn Newbie

      Hi,

      I have a lot of problems with deadlocks and I have tried a lot of different configuration and none have worked (I will soon post some questions about this). So my new strategy is to rollback and retry the transactions which fails. However, I have realized that I do not understand everything about transactions.

      Here is the flow of method invocations:
      (1) Servlet -> (2) stateful session bean -> (3) several entity beans

      First attempt:

      (2) has a method request() with transaction type "Required"
      I also use context.setRollBackOnly() in the session bean if something other than deadlock problems happens during the execution.

      (1) contains something like the following..

      while(!success && k<3)
      {
      try
      {
      session.request();
      success = true
      }
      // catch rollback and deadlock exception
      catch(Exception e)
      {
      success = false,
      e.printStackTrace();
      k++;
      }
      }

      Questions:
      Is this the correct way to handle the transaction rollback?
      I hope I don't have to call a specific method to actually perform the rollback?
      I also read somewhere on this forum that JBoss automatically retries transaction when deadlock occurs, is that true?

      Anyway, the code above seems to work in most cases.

      Attempt two:

      I don't to want to catch the exceptions in the servlet so I moved the code above to a new method in the session ejb called testRequest(), which the servlet invokes. testRequest() then calls the original request() method.

      I used "Required" for testRequest() and "RequiresNew() for request(). My thought was that a new transaction would be created and that would be the transaction that would be rolled back in case of problems.

      (2)

      testRequest()
      {
      while(!success && k<3)
      {
      try
      {
      request();
      success = true
      }
      // catch rollback and deadlock exception
      catch(Exception e)
      {
      success = false,
      k++;
      }
      }
      }

      This didnt work as I expected, the transaction rolled back but it is never restarted , instead it stayed in the rollback state. I tried to invoke context.getRollbackOnly() in testRequest() and it returned "True". So I guess that the transaction which is started when the servlet calls testRequest() is rolled back as well, I thought that only the second transaction which is created when request() is called would rollback..

      Questions:
      Will a rollback propagate all the way back to the original transaction if "RequiresNew" is used?
      Is there a way to catch and retry the transaction rollbacks in the actual session bean instead of in the servlet?

      I hope someone can make some sense of what I wrote above :)

      Thanks in advance
      /Lars