[jboss-user] [EJB3] - Does a LockAcquisitionException Invalidate a Transaction?

Sam Smith do-not-reply at jboss.com
Fri Apr 13 11:14:01 EDT 2012

Sam Smith [https://community.jboss.org/people/ssmith2010] created the discussion

"Does a LockAcquisitionException Invalidate a Transaction?"

To view the discussion, visit: https://community.jboss.org/message/729932#729932

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:

public List getData(args...)

int retries=0;
boolean continue=true:

while (continue) {
     continue = false;
          hibernate query to SELECT data
     catch (Exception ex)
          if (ex instanceof LockAcquisitionException) {
               if (retries < 5) continue = true;


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.

Reply to this message by going to Community

Start a new discussion in EJB3 at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120413/22911a4a/attachment-0001.html 

More information about the jboss-user mailing list