public static DataAccessException convertHibernateAccessException(HibernateException ex) {
if (ex instanceof JDBCConnectionException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof SQLGrammarException) {
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
}
if (ex != null && "org.hibernate.exception.DataException".equals(ex.getClass().getName())) {
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
}
if (ex instanceof LockAcquisitionException) {
return new CannotAcquireLockException(ex.getMessage(), ex);
}
if (ex instanceof ConstraintViolationException) {