public static DataAccessException ConvertHibernateAccessException(HibernateException ex)
{
if (ex is ADOException)
{
// ADOException during Hibernate access: only passed in here from custom code,
// as HibernateTemplate etc will use AdoExceptionTranslator-based handling.
return new HibernateAdoException("Ado Exception", (ADOException) ex);
}
if (ex is UnresolvableObjectException)
{
return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex);
}
if (ex is ObjectDeletedException)
{
return new InvalidDataAccessApiUsageException(ex.Message, ex);
}
if (ex is WrongClassException)
{
return new HibernateObjectRetrievalFailureException((WrongClassException) ex);
}
if (ex is StaleObjectStateException)
{
return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex);
}
if (ex is StaleStateException)
{
return new HibernateOptimisticLockingFailureException((StaleStateException)ex);
}
if (ex is QueryException)
{
return new HibernateQueryException((QueryException) ex);
}
if (ex is PersistentObjectException)
{
return new InvalidDataAccessApiUsageException(ex.Message, ex);
}
if (ex is TransientObjectException)
{
return new InvalidDataAccessApiUsageException(ex.Message, ex);
}
if (ex is PropertyValueException)
{
return new DataIntegrityViolationException(ex.Message, ex);
}
if (ex is PersistentObjectException)
{
return new InvalidDataAccessApiUsageException(ex.Message, ex);
}
if (ex is NonUniqueResultException)
{
return new IncorrectResultSizeDataAccessException(ex.Message, 1);
}
// fallback
return new HibernateSystemException(ex);
}