Where are you opening you NHibernate transactions?

/Oskar


2010/11/4 Palmer Eldritch <[email protected]>:
> Hi,
> I'm experiencing some issues with Nhibernate, distributed transactions and
> transactionScope (system.Transactions).
> In a nutshell, I am unable to use transactionscope and distributed
> transactions without adding explicit flushes.
> The problematic usage pattern boils down to this:
> using (var tx = new TransactionScope())
> {
>    // query on session 1
>    // query on session 2
>    // save/persist something on session1
>    tx.Complete();
> }
> In this usage pattern an exception will be thrown when leaving the using
> block.
> The exception is a TransactionException with message "The operation is not
> valid for the state of the transaction."
> it also has an inner exception that is a SqlException with a timeout
> message.
> The timeout occurs on the insert command that results from the Session.Save.
> The code works when either of the queries is not performed but not when both
> are performed.
> I have attached a repro case where you can experiment with this scenario, I
> used NH 3b2 and use NH 2.1.2 in the actual production code.
> I have also tried to emulate how nhibernate works with distributed
> transaction (as far as I understand from tracing through the code) and I can
> reproduce this issue also with vanilla ADO code (hence the may not actually
> be an nh issue qualifier).
> I wouldn't exclude an architectural problem with flushing the sessions in
> the Prepare method of the EnlistmentNotification but I freely admit I have
> no proof to back this up. The only thing that strikes me as odd is that the
> sql transaction gets committed after the tx.Complete call while the sessions
> only get flushed when the TransactionScope gets disposed on leaving the
> using block.
> In my searches for answers I hit this thread which as far as I can see deals
> with the same issue but there doesn't seem to be any resolution.
> http://www.mail-archive.com/[email protected]/msg02391.html
> for the moment I can get by with explicitly flushing the sessions before the
> tx.Complete() but that really sucks, as would having to explicitly start and
> commit/rollback nhibernate transactions.
> I would be interested if to know if anybody can a) actually reproduce the
> issue, b) can explain why things happen as theydo and last but definitely
> not least c) knows how to fix this.
> Thanks

Reply via email to