@Override public RuntimeException convert(HibernateException e, LockOptions lockOptions) { Throwable cause = e; if (cause instanceof StaleStateException) { final PersistenceException converted = wrapStaleStateException((StaleStateException) cause); handlePersistenceException(converted); return converted; } else if (cause instanceof LockingStrategyException) { final PersistenceException converted = wrapLockException((HibernateException) cause, lockOptions); handlePersistenceException(converted); return converted; } else if (cause instanceof org.hibernate.exception.LockTimeoutException) { final PersistenceException converted = wrapLockException((HibernateException) cause, lockOptions); handlePersistenceException(converted); return converted; } else if (cause instanceof org.hibernate.PessimisticLockException) { final PersistenceException converted = wrapLockException((HibernateException) cause, lockOptions); handlePersistenceException(converted); return converted; } else if (cause instanceof org.hibernate.QueryTimeoutException) { final QueryTimeoutException converted = new QueryTimeoutException(cause.getMessage(), cause); handlePersistenceException(converted); return converted; } else if (cause instanceof ObjectNotFoundException) { final EntityNotFoundException converted = new EntityNotFoundException(cause.getMessage()); handlePersistenceException(converted); return converted; } else if (cause instanceof org.hibernate.NonUniqueObjectException) { final EntityExistsException converted = new EntityExistsException(cause.getMessage()); handlePersistenceException(converted); return converted; } else if (cause instanceof org.hibernate.NonUniqueResultException) { final NonUniqueResultException converted = new NonUniqueResultException(cause.getMessage()); handlePersistenceException(converted); return converted; } else if (cause instanceof UnresolvableObjectException) { final EntityNotFoundException converted = new EntityNotFoundException(cause.getMessage()); handlePersistenceException(converted); return converted; } else if (cause instanceof QueryException) { return new IllegalArgumentException(cause); } else if (cause instanceof MultipleBagFetchException) { return new IllegalArgumentException(cause); } else if (cause instanceof TransientObjectException) { try { sharedSessionContract.markForRollbackOnly(); } catch (Exception ne) { // we do not want the subsequent exception to swallow the original one log.unableToMarkForRollbackOnTransientObjectException(ne); } return new IllegalStateException(e); // Spec 3.2.3 Synchronization rules } else { final PersistenceException converted = new PersistenceException(cause); handlePersistenceException(converted); return converted; } }
private void handlePersistenceException(PersistenceException e) { if (e instanceof NoResultException) { return; } if (e instanceof NonUniqueResultException) { return; } if (e instanceof LockTimeoutException) { return; } if (e instanceof QueryTimeoutException) { return; } try { sharedSessionContract.markForRollbackOnly(); } catch (Exception ne) { // we do not want the subsequent exception to swallow the original one log.unableToMarkForRollbackOnPersistenceException(ne); } }