0 Replies Latest reply on Apr 13, 2012 11:13 AM by ssmith2010

    Does a LockAcquisitionException Invalidate a Transaction?

    ssmith2010

      We're using Hibernate with SQL Server.  As you may know, SQL Server will occassionally throw deadlocks during SELECT statements.  We'd like to be able to capture this exception and retry the SELECT statement.  Our preference would be to do this globally in our EJB (which ises CMP), something like this:

       

      {code}

      public List getData(args...)

       

      int retries=0;

      boolean continue=true:

       

      while (continue) {

      try

           continue = false;

           {

                hibernate query to SELECT data

           }

           catch (Exception ex)

           {

                if (ex instanceof LockAcquisitionException) {

                     retries++;

                     if (retries < 5) continue = true;

                   }

           }

      }

       

      {code}

       

      So the idea is to do the query, if there's a LockAcquisitionException, just retry a couple of time.  Our only concern is this -- does the exception invalidate the transaction?  We know the transaction is started when we enter the method, so if within the method we get an error, can we just retry or is the transaction no longer any good?  I'm sure it would be no good if we were doing an update and it forced a ROLLBACK, but we're unsure about in a non-update statement.