[SPRNET-779] NHibernateTransactionManager can not convert AdoAcessException Created: 23/Nov/07  Updated: 07/Dec/07  Resolved: 07/Dec/07

Status: Resolved
Project: Spring.NET
Component/s: Spring-NET-NH, Spring-NET-TX
Affects Version/s: 1.1 RC2
Fix Version/s: 1.1.0

Type: Bug Priority: Major
Reporter: cagatay kalan Assignee: Mark Pollack
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows XP SP2, Sql Server 2005



 Description   

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

{ adoExceptionTranslator = value; }

get
{
if (adoExceptionTranslator == null)

{ adoExceptionTranslator = SessionFactoryUtils.NewAdoExceptionTranslator(SessionFactory); }

return adoExceptionTranslator;
}
}

which i copied from HibernateTemplate. Now the AdoException is being converted.



 Comments   
Comment by Mark Pollack [ 26/Nov/07 ]

Hi, Thanks for reporting this. The same issue was reported a little while ago and it is now fixed. See SPRNET-778 for more info. You can pick up the latest nightly build and/or make the changes in this cvs commit ( http://fisheye1.cenqua.com/changelog/springnet/?cs=MAIN:markpollack:20071120040343 ) to your local commit.

Generated at Fri Aug 14 14:06:11 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.