Ah, OK, thank you! :)

-Michael

________________________________
From: [email protected] 
[[email protected]] On Behalf Of Ayende Rahien 
[[email protected]]
Sent: Thursday, February 18, 2010 8:55 AM
To: [email protected]
Subject: Re: [nhibernate-development] Re: AdoNetWithDistrubtedTransactionFactory

They aren't needed, you can use either or both.
The important thing to remember is just that you can't recover from either an 
exception or a rollback

On Thu, Feb 18, 2010 at 6:48 PM, Michael Teper 
<[email protected]<mailto:[email protected]>> wrote:
Fabio,

Does that mean the correct pattern is:

public void DoSomething()
{
  using (var scope = new TransactionScope())
  {
    var s = SessionFactory.OpenSession();
    s.BeginTransaction();

    var foo = s.Get<Foo>();
    foo.Prop = "bar";
    s.SaveOrUpdate(foo);

    s.CommitTransaction();
    scope.Complete();
  }
}

If so, why are BeginTransaction and CommitTransaction needed? They feel 
redundant...

Thank you!
-Michael


________________________________
From: 
[email protected]<mailto:[email protected]>
 
[[email protected]<mailto:[email protected]>]
 On Behalf Of Fabio Maulo [[email protected]<mailto:[email protected]>]
Sent: Thursday, February 18, 2010 6:53 AM

To: 
[email protected]<mailto:[email protected]>
Subject: Re: [nhibernate-development] Re: AdoNetWithDistrubtedTransactionFactory

In order to use NH correctly you should:
1) throw away the session after an exception
2) use the NH's transaction

Use NH's transaction mean:
1) open the session inside a transactionscope
2) after open the session begin a NH's transaction using 
session.BeginTransaction

2010/2/18 Sathish Naga <[email protected]<mailto:[email protected]>>
The test is reflecting the way I use the NH session and transaction
scope.

When I run the test with the default transaction
factory(AdoNetWithDistrubtedTransactionFactory), it fails on first
session.Clear.

When I override the Session Factory to use the AdoTransactionFactory,
sample test didn't fail on first session.Clear().

I have the test as patch, if you want I can send/upload it.

Thanks
Sathish

On Feb 17, 9:51 pm, Fabio Maulo 
<[email protected]<mailto:[email protected]>> wrote:
> Where is the NH's transaction ? (ITransaction)
> I mean... you said you have a issue
> with AdoNetWithDistrubtedTransactionFactory but in your code you haven't use
> it, so... where is the issue ?
>
> 2010/2/17 Sathish Naga <[email protected]<mailto:[email protected]>>
>
>
>
>
>
> > Hi,
>
> > I've a issue with NHibernate 2.1x and
> > AdoNetWithDistrubtedTransactionFactory and SessionImpl.
>
> > To give you background of my Infrastructure, I have a NH session
> > created per web request.
>
> > On Begin Request I create a Session and On End Request, I clear and
> > dispose the NH session.
>
> > using (ISession s = sessions.OpenSession())
> > {
> >        s.FlushMode = FlushMode.Commit;
>
> >        using (var tx = new
> > TransactionScope(TransactionScopeOption.Required,
> > new TimeSpan(0,0,0,0,10000)))
>
> >                                  //
> > Set timeout to 10 secs
> >        {
> >                try
> >                {
> >                        s.Save(new Person { CreatedAt = DateTime.Now});
> >                        Thread.Sleep(20000); //Sleep for 20 secs to timeout
> > the transaction
> >                        s.Flush();
> >                        tx.Complete();
> >                }
> >                catch (Exception ex)
> >                {
> >                        //when this transaction fails, clear internal entity
> > cache on
> > session and move on
> >                        s.Clear();//
> >                }
> >        }
> >       //This transaction expected to be successful
> >        using (var tx = new TransactionScope())
> >        {
> >                try
> >                {
> >                        s.Save(new Person { CreatedAt = DateTime.Now });
> >                        s.Flush();
> >                        tx.Complete();
> >                }
> >                catch (Exception ex)
> >                {
> >                        s.Clear();
> >                }
> >        }
> > }
>
> > As i reuse the same session for multiple transactions, when any of my
> > transaction fails, I want to clear the session internal cache. In that
> > case when the error is due to TransactionScope it fails on
> > session.clear and brings whole application down.
>
> > Once JIRA is up, I'm going to add this defect. I have the test
> > created, Looks like I cant attach the patch to this mail.
>
> --
> Fabio Maulo



--
Fabio Maulo


Reply via email to