NH-2181

http://216.121.112.228/browse/NH-2181



-Carlos

 

Practice makes perfect, but if no one is perfect, why practice?




Date: Thu, 22 Apr 2010 09:18:57 -0300
Subject: Re: [nhusers] Re: Connection leak when ambient transaction aborts
From: [email protected]
To: [email protected]

Let me guess: you're using identity. 
    Diego



On Thu, Apr 22, 2010 at 04:45, Norman <[email protected]> wrote:

Thanks for your quick responses on this.



However I still don't understand why an NHibernate transaction is

required in addition to TransactionScope. I've written a test (below)

and TransactionScope works without the need to create an NHibernate

transaction.



The result is that Richard and Simon are saved to the database, but

Norman is rolled back.



What additional benefit do you get from also calling

"session.BeginTransaction()"?





        public void TransactionScopeTest()

        {

            Person norman = new Person() { Name = "Norman" };

            Person richard = new Person() { Name = "Richard" };

            Person simon = new Person() { Name = "Simon" };



            using (ISession s1 = OpenSession())

            {

                using (TransactionScope scope = new

TransactionScope())

                {

                    s1.Save(norman);



                    // do not complete so automatically rollback

                }

            }



            using (ISession s2 = OpenSession())

            {

                using (TransactionScope scope = new

TransactionScope())

                {

                    s2.Save(richard);



                    scope.Complete();

                }

            }



            using (ISession s3 = OpenSession())

            {

                s3.Save(simon);

            }

        }







On Apr 21, 2:38 pm, Diego Mijelshon <[email protected]> wrote:

> Norman,

>

> It's simple: your assumption is not correct.

> NHibernate transactions automatically enlist in the scope transactions, but

> they are still needed (i.e. having a TransactionScope does NOT create a NH

> transaction)

>

>    Diego

>

>

>

>

>

> On Wed, Apr 21, 2010 at 09:57, Norman <[email protected]> wrote:

> > Diego - can you please explain why both "new TransactionScope()" and

> > "session.BeginTransaction()" are required? My understanding is that

> > when using TransactionScope there is no need to create a transaction

> > with the session as one is created automatically.

>

> > Thanks.

>

> > --

> > You received this message because you are subscribed to the Google Groups

> > "nhusers" group.

> > To post to this group, send email to [email protected].

> > To unsubscribe from this group, send email to

> > [email protected]<nhusers%[email protected]­>


> > .

> > For more options, visit this group at

> >http://groups.google.com/group/nhusers?hl=en.

>

> --

> You received this message because you are subscribed to the Google Groups 
> "nhusers" group.

> To post to this group, send email to [email protected].

> To unsubscribe from this group, send email to 
> [email protected].

> For more options, visit this group 
> athttp://groups.google.com/group/nhusers?hl=en.- Hide quoted text -

>

> - Show quoted text -



--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.

To post to this group, send email to [email protected].

To unsubscribe from this group, send email to 
[email protected].

For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.









-- 

You received this message because you are subscribed to the Google Groups 
"nhusers" group.

To post to this group, send email to [email protected].

To unsubscribe from this group, send email to 
[email protected].


For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.
                                          

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to