List of usage examples for org.springframework.orm.hibernate5 HibernateOptimisticLockingFailureException HibernateOptimisticLockingFailureException
public HibernateOptimisticLockingFailureException(OptimisticEntityLockException ex)
From source file:org.springframework.orm.hibernate5.SessionFactoryUtils.java
/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * @param ex HibernateException that occurred * @return the corresponding DataAccessException instance * @see HibernateExceptionTranslator#convertHibernateAccessException * @see HibernateTransactionManager#convertHibernateAccessException *//* w w w . ja v a 2 s .c om*/ public static DataAccessException convertHibernateAccessException(HibernateException ex) { if (ex instanceof JDBCConnectionException) { return new DataAccessResourceFailureException(ex.getMessage(), ex); } if (ex instanceof SQLGrammarException) { SQLGrammarException jdbcEx = (SQLGrammarException) ex; return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof QueryTimeoutException) { QueryTimeoutException jdbcEx = (QueryTimeoutException) ex; return new org.springframework.dao.QueryTimeoutException( ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof PessimisticLockException) { PessimisticLockException jdbcEx = (PessimisticLockException) ex; return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof ConstraintViolationException) { ConstraintViolationException jdbcEx = (ConstraintViolationException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex); } if (ex instanceof DataException) { DataException jdbcEx = (DataException) ex; return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof JDBCException) { return new HibernateJdbcException((JDBCException) ex); } // end of JDBCException (subclass) handling if (ex instanceof QueryException) { return new HibernateQueryException((QueryException) ex); } if (ex instanceof NonUniqueResultException) { return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex); } if (ex instanceof NonUniqueObjectException) { return new DuplicateKeyException(ex.getMessage(), ex); } if (ex instanceof PropertyValueException) { return new DataIntegrityViolationException(ex.getMessage(), ex); } if (ex instanceof PersistentObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof TransientObjectException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof ObjectDeletedException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } if (ex instanceof UnresolvableObjectException) { return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex); } if (ex instanceof WrongClassException) { return new HibernateObjectRetrievalFailureException((WrongClassException) ex); } if (ex instanceof StaleObjectStateException) { return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex); } if (ex instanceof StaleStateException) { return new HibernateOptimisticLockingFailureException((StaleStateException) ex); } if (ex instanceof OptimisticEntityLockException) { return new HibernateOptimisticLockingFailureException((OptimisticEntityLockException) ex); } if (ex instanceof PessimisticEntityLockException) { if (ex.getCause() instanceof LockAcquisitionException) { return new CannotAcquireLockException(ex.getMessage(), ex.getCause()); } return new PessimisticLockingFailureException(ex.getMessage(), ex); } // fallback return new HibernateSystemException(ex); }