Sathish, The only scenario that I can see is if you are using it in your tests.
On Thu, Feb 18, 2010 at 10:15 PM, Sathish Naga <[email protected]> wrote: > > Thanks Ayende and Fabio for your comments. I need to change the way I > use the session. > > Can you guys throw some light on Session.Clear() method, when it can > be used ? > > I appreciate your help. > > Thanks > > On Feb 18, 8:53 am, Fabio Maulo <[email protected]> wrote: > > 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]> > > > > > > > > > > > > > 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]> 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]> > > > > > > > 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 >
