The test is not valid. That it works the way you expect is coincidence,
rather than by design. Try adding a few seconds delay after session 2 and
before opening session 3. If you are using an automatic flush then it will
probably occur before before the session 3 open and that save will fail.

John Davidson

On Thu, Apr 22, 2010 at 3:45 AM, 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]>
> <nhusers%[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]<nhusers%[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]<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 at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to