-
Type:
Bug
-
Status: Resolved
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 1.1 RC2
-
Fix Version/s: 1.1.0
-
Component/s: Spring-NET-NH, Spring-NET-TX
-
Labels:None
-
Environment:Windows XP SP2, Sql Server 2005
When you use OpenSessionInView module in a web application and use HibernateTransactionManager, you get "NullReferenceException" in response to a AdoException at "HibernateTransactionManager.ConvertAdoAccessException" method. The code i tried is as follows:
This is the dao method,
[Transaction(ReadOnly = false)]
public void Save(Product product)
{
this.HibernateTemplate.Save(product);
}
I have copied the configuration from the Spring.Data.NHibernate.Northwind project in examples folder.
I checked the source files and I think that, because there is an existing transaction HibernateTemplate does not flush the session. So the exception is not thrown from HibernateTemplate. At the end of the transaction, HibernateTransactionManager tries to commit the transaction and NullReferenceException occurs because "adoExceptionTranslator" field of the transaction manager is null. The documentation does not tell about how to set an AdoExceptionTranslator to this field. I think the main problem is that, if you use HibernateTransactionManager, HibernateTemplate's error handling becomes useless.
I changed the getter of "AdoExceptionTranslator" in "HibernateTransactionManager" as the following,
public IAdoExceptionTranslator AdoExceptionTranslator
{
set
get
{
if (adoExceptionTranslator == null)
return adoExceptionTranslator;
}
}
which i copied from HibernateTemplate. Now the AdoException is being converted.