nhibernatetransactionsspring.netfluent

Fluent mappings and Spring .NET transactions not working together


I am facing a weird problem with Fluent, NHibernate and Spring.net. My project is an ASP.NET MVC 2.0 (.net 4.0) project.

I created my project based on Spring.net Nhibnernate Northwind project. I am also using Fluent code based mappings as suggested on this page http://blog.bennymichielsen.be/2009/01/04/using-fluent-nhibernate-in-spring-net.

When I apply tx:attribute-driven to my spring context xml file, it breaks the application. The LocalSessionFactoryObject is not injected in my DAOs. I tried pulling the SessionFactory manually from the context, the app works but the transactions are not rolled back.

If I remove the tx:attribute-driven attribute, the app works but of course the transactions are not rolled back. The logs dont show any errors. Since the app is working without the attribute, I am guessing most of my configuration should be ok.

Has anyone used a combination of Fluent, Nhibernate and Spring.net successfully with Transactions?

I can provide more details about my setup if necessary.


Solution

  • I figured it out myself. In case someone else is having problems with Transactions or any spring supplied features related to AOP, please make sure you are programming against Interfaces and not concrete classes. Somehow I was missing this. If you use concrete classes, your code will not be able to use the special proxies created by Spring and the features like TX management will not be available.