Ayush
Ayush

Reputation: 63

How can I add nested transactions in NHibernate?

I have a use case where I am processing multiple configuration within a function, each configuration processing runs within a separate transaction and transaction gets commited if everything is fine, now if at all anything goes wrong in processing of further configuration I want to revert all the commuted transaction. Can anyone please help me with code snippet? My application is on .net.

Upvotes: 0

Views: 277

Answers (2)

Oskar Berggren
Oskar Berggren

Reputation: 5629

It's not a matter of using nested transactions. It's a matter of ensuring that you have a transaction that surrounds all the relevant code - so it should be open/closed "higher up". Each individual section should then either not care about transactions at all, or it should "piggy-back" on any existing transaction and only open a new transaction when one does not already exist.

As a guideline, transaction management is an overall concern that should be handled in different sorts of wrapper methods and applied as needed by the application - not hidden away in specific low-level support routines.

Upvotes: 0

David Osborne
David Osborne

Reputation: 6781

To the best of my knowledge, NH doesn't support nested transactions.

You can use a transaction at the root of your use case, or at any point along the way, but it's all or nothing, AFAIK.

Upvotes: 1

Related Questions