NH will enlist its transactions in the transactionscope, but they are not
optional.
Diego
On Thu, Aug 26, 2010 at 08:19, MixMasta <[email protected]> wrote:
> I don't have the option of using a nhibernate transaction in my
> scenario.
> NHibernate has support for transactionscope so it should enlist in the
> transaction.
>
> On Aug 26, 12:52 pm, Jason Dentler <[email protected]> wrote:
> > First, you must use an NHibernate transaction for all database
> interaction.
> > TransactionScope is not a substitute.
> >
> > Second, TransactionScope should only be used when you need to coordinate
> > more than one resource. Even then, you should still use an NHibernate
> > transaction as well.
> >
> > Third, TransactionScope allows each resource to vote whether the
> transaction
> > should be rolled back or committed. If everyone votes commit, then it's
> > committed. When you use a real NH transaction, you can control which way
> > NHibernate will vote.
> >
> > On Thu, Aug 26, 2010 at 1:12 AM, MixMasta <[email protected]> wrote:
> > > I am using a .NET transaction scope and running the following to
> > > verify transaction commits/rollbacks
> > > Using 2.1 nhibernate talking to SQL server db.
> >
> > > var b1 = new Person {Email = "[email protected]", Username = "art"};
> > > using (var session = NHibernateSession.CurrentFor("MyDatabase"))
> > > {
> > > session.Save(b1);
> > > session.Flush();
> > > }
> > > //Writes b1 away to database
> >
> > > using (var tx = new TransactionScope())
> > > {
> > > using (var session = NHibernateSession.CurrentFor("MyDatabase"))
> > > {
> > > var b2 = (Person)session.Load(typeof(Person), b1.Id);
> > > b2.Username = "art1234";
> > > session.Flush();
> > > }
> > > tx.Complete();
> > > }
> >
> > > using (var session = NHibernateSession.CurrentFor("MyDatabase"))
> > > {
> > > var b3 = (Person)session.Load(typeof(Person), b1.Id);
> > > Assert.IsTrue(b3.Username == "art");
> > > }
> >
> > > If I leave the session.Flush() uncommented the transaction commits
> > > even if I have the tx.Complete() commented out - I was expecting the
> > > transaction scope to decide whether to commit those changes. If I
> > > comment out session.Flush() and don't set tx.Complete() then the
> > > transaction rolls back as expected.
> >
> > > My guess is that session.Flush creates its own implicit transaction
> > > and commits it and ignores the current .NET transaction scope.
> >
> > > 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 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.