SPRNET-1205 - ExecuteFind tries to throw ConvertADOAccessException but throws NullReferenceException

This commit is contained in:
markpollack
2010-12-10 22:56:55 +00:00
parent 3fb538d1e6
commit 707edcb3fc
3 changed files with 36 additions and 13 deletions

View File

@@ -444,15 +444,9 @@ namespace Spring.Data.NHibernate
/// <returns>
/// the corresponding DataAccessException instance
/// </returns>
protected virtual DataAccessException ConvertAdoAccessException(ADOException ex)
protected virtual DataAccessException ConvertAdoAccessException(ADOException ex)
{
string sqlString = (ex.SqlString != null)
? ex.SqlString.ToString()
: string.Empty;
return AdoExceptionTranslator.Translate(
"Hibernate operation: " + ex.Message, sqlString, ex.InnerException);
return SessionFactoryUtils.ConvertAdoAccessException(AdoExceptionTranslator, ex);
}
/// <summary>

View File

@@ -401,6 +401,39 @@ namespace Spring.Data.NHibernate
#endregion
/// <summary>
/// Converts a Hibernate ADOException to a Spring DataAccessExcption, extracting the underlying error code from
/// ADO.NET. Will extract the ADOException Message and SqlString properties and pass them to the translate method
/// of the provided IAdoExceptionTranslator.
/// </summary>
/// <param name="translator">The IAdoExceptionTranslator, may be a user provided implementation as configured on
/// HibernateTemplate.
/// </param>
/// <param name="ex">The ADOException throw</param>
/// <returns>The translated DataAccessException or UncategorizedAdoException in case of an error in translation
/// itself.</returns>
public static DataAccessException ConvertAdoAccessException(IAdoExceptionTranslator translator, ADOException ex)
{
try
{
string sqlString = (ex.SqlString != null)
? ex.SqlString.ToString()
: string.Empty;
return translator.Translate(
"Hibernate operation: " + ex.Message, sqlString, ex.InnerException);
} catch (Exception e)
{
log.Error("Exception thrown during exception translation. Message = [" + e.Message + "]", e);
log.Error("Exception that was attempted to be translated was [" + ex.Message + "]", ex);
if (ex.InnerException != null)
{
log.Error(" Inner Exception was [" + ex.InnerException.Message + "]", ex.InnerException);
}
throw new UncategorizedAdoException(e.Message, "", "", e);
}
}
/// <summary>
/// Convert the given HibernateException to an appropriate exception from the
/// <code>Spring.Dao</code> hierarchy. Note that it is advisable to

View File

@@ -1062,11 +1062,7 @@ namespace Spring.Data.NHibernate
/// </returns>
protected virtual DataAccessException ConvertAdoAccessException(ADOException ex)
{
string sqlString = (ex.SqlString != null) ? ex.SqlString.ToString() : string.Empty;
return AdoExceptionTranslator.Translate(
"Hibernate operation: " + ex.Message, sqlString, ex.InnerException);
return SessionFactoryUtils.ConvertAdoAccessException(AdoExceptionTranslator, ex);
}
#endregion