I've been using Spring.NET declarative Transaction management for some time in a code base that uses IBatis in conjunction with the TxScopeTransactionManager. I just added Spring.NET NHibernate support to the project (using OSIV pattern) without issue. NHibernate will be used for new features only, ADO.NET/IBatis legacy data access code still needs to work as is. So I now have two distinct transaction managers in my context:
- Spring.Data.Core.TxScopeTransactionManager (existing Tran Mgr)
- Spring.Data.NHibernate.HibernateTransactionManager (added for Nhibernate)
However, it looks like Spring.NET only allows a single TransactionManager to be bound to the Transaction attribute because legacy service methods decorated with this attribute are now using HibernateTransactionManager instead of TxScopeTransactionManager to commit or rollback transactions. This is problematic since HibernateTransactionManager is not aware of any non-nHibernate (read ADO.NET) connections.
Is there a way to have [Transaction] use different Transaction Managers, perhaps in concert with the ObjectNameAutoProxyCreator to either include/exclude service classes based on namespace?
If not, is there a way to have a single transactionManager handle both NHibernate and IBatis transactions?
I tested this using HibernateTransactionManager to manage both Data Access strategies, but my IBatis transactions aren't getting rolled back. This is particularly odd, because I can see in SQL Profiler that both a Begin Tran and Rollback Tran are being sent by HibernateTransactionManager, but the data still gets committed.
If I use TxScopeTransactionManager, then my IBatis transactions rollback successfully but NHibernate writes to the DB are never flushed.