Example #1
0
 /// <summary>
 /// Convert the given HibernateException to an appropriate exception from the
 /// <code>org.springframework.dao</code> hierarchy. Will automatically detect
 /// wrapped ADO.NET Exceptions and convert them accordingly.
 /// </summary>
 /// <param name="ex">HibernateException that occured.</param>
 /// <returns>
 /// The corresponding DataAccessException instance
 /// </returns>
 /// <remarks>
 /// The default implementation delegates to SessionFactoryUtils
 /// and convertAdoAccessException. Can be overridden in subclasses.
 /// </remarks>
 public virtual DataAccessException ConvertHibernateAccessException(HibernateException ex)
 {
     if (ex is ADOException)
     {
         return ConvertAdoAccessException((ADOException) ex);
     }   
     return SessionFactoryUtils.ConvertHibernateAccessException(ex);
 }
Example #2
0
 /// <summary>
 /// Convert the given HibernateException to an appropriate exception from the
 /// <code>org.springframework.dao</code> hierarchy. Will automatically detect
 /// wrapped ADO.NET Exceptions and convert them accordingly.
 /// </summary>
 /// <param name="ex">HibernateException that occured.</param>
 /// <returns>
 /// The corresponding DataAccessException instance
 /// </returns>
 /// <remarks>
 /// The default implementation delegates to SessionFactoryUtils
 /// and convertAdoAccessException. Can be overridden in subclasses.
 /// </remarks>
 protected DataAccessException ConvertHibernateAccessException(HibernateException ex)
 {
     return hibernateTemplate.ConvertHibernateAccessException(ex);
 }
 /// <summary>
 /// Convert the given HibernateException to an appropriate exception from
 /// the Spring.Dao hierarchy. Can be overridden in subclasses.
 /// </summary>
 /// <param name="ex">The HibernateException that occured.</param>
 /// <returns>The corresponding DataAccessException instance</returns>
 protected virtual DataAccessException ConvertHibernateAccessException(HibernateException ex)
 {
     if (AdoExceptionTranslator != null && ex is ADOException)
     {
         return ConvertAdoAccessException((ADOException)ex, AdoExceptionTranslator);
     }
     else if (ex is ADOException)
     {
         return ConvertAdoAccessException((ADOException)ex, DefaultAdoExceptionTranslator);
     }
     return SessionFactoryUtils.ConvertHibernateAccessException(ex);
 }
Example #4
0
        /// <summary>
        /// Convert the given HibernateException to an appropriate exception from the
        /// <code>Spring.Dao</code> hierarchy. Note that it is advisable to
        /// handle AdoException specifically by using a AdoExceptionTranslator for the
        /// underlying ADO.NET exception.
        /// </summary>
        /// <param name="ex">The Hibernate exception that occured.</param>
        /// <returns>DataAccessException instance</returns>
        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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HibernateSystemException"/> class.
 /// </summary>
 /// <param name="cause">The cause.</param>
 public HibernateSystemException(HibernateException cause)
     : base(cause != null ? cause.Message : null, cause)
 {
 }