Search in sources :

Example 6 with LockTimeoutException

use of javax.persistence.LockTimeoutException in project hibernate-orm by hibernate.

the class ExceptionConverterImpl method wrapLockException.

protected PersistenceException wrapLockException(HibernateException e, LockOptions lockOptions) {
    final PersistenceException pe;
    if (e instanceof OptimisticEntityLockException) {
        final OptimisticEntityLockException lockException = (OptimisticEntityLockException) e;
        pe = new OptimisticLockException(lockException.getMessage(), lockException, lockException.getEntity());
    } else if (e instanceof org.hibernate.exception.LockTimeoutException) {
        pe = new LockTimeoutException(e.getMessage(), e, null);
    } else if (e instanceof PessimisticEntityLockException) {
        final PessimisticEntityLockException lockException = (PessimisticEntityLockException) e;
        if (lockOptions != null && lockOptions.getTimeOut() > -1) {
            // assume lock timeout occurred if a timeout or NO WAIT was specified
            pe = new LockTimeoutException(lockException.getMessage(), lockException, lockException.getEntity());
        } else {
            pe = new PessimisticLockException(lockException.getMessage(), lockException, lockException.getEntity());
        }
    } else if (e instanceof org.hibernate.PessimisticLockException) {
        final org.hibernate.PessimisticLockException jdbcLockException = (org.hibernate.PessimisticLockException) e;
        if (lockOptions != null && lockOptions.getTimeOut() > -1) {
            // assume lock timeout occurred if a timeout or NO WAIT was specified
            pe = new LockTimeoutException(jdbcLockException.getMessage(), jdbcLockException, null);
        } else {
            pe = new PessimisticLockException(jdbcLockException.getMessage(), jdbcLockException, null);
        }
    } else {
        pe = new OptimisticLockException(e);
    }
    return pe;
}
Also used : PessimisticEntityLockException(org.hibernate.dialect.lock.PessimisticEntityLockException) PersistenceException(javax.persistence.PersistenceException) OptimisticLockException(javax.persistence.OptimisticLockException) LockTimeoutException(javax.persistence.LockTimeoutException) OptimisticEntityLockException(org.hibernate.dialect.lock.OptimisticEntityLockException) PessimisticLockException(javax.persistence.PessimisticLockException)

Aggregations

LockTimeoutException (javax.persistence.LockTimeoutException)6 HashMap (java.util.HashMap)5 EntityManager (javax.persistence.EntityManager)5 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)5 Test (org.junit.Test)5 Callable (java.util.concurrent.Callable)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 RequiresDialect (org.hibernate.testing.RequiresDialect)4 PersistenceException (javax.persistence.PersistenceException)2 PessimisticLockException (javax.persistence.PessimisticLockException)2 OptimisticLockException (javax.persistence.OptimisticLockException)1 OptimisticEntityLockException (org.hibernate.dialect.lock.OptimisticEntityLockException)1 PessimisticEntityLockException (org.hibernate.dialect.lock.PessimisticEntityLockException)1 TestForIssue (org.hibernate.testing.TestForIssue)1