usually transactions are rolled back when an error is thrown. if an
error is thrown the session should be disposed of and a new one
opened. in the test case an exception is not thrown, the transaction
is rolled back and the session is not replaced. the session is holding
the entity in the identity map with the updated value. so the second
Get<> call is returning the item in the identity map, not the
database.
var value = "new text";
using(var ts = new TransactionScope())
using(var session = factory.OpenSession())
{
session.Get<Entity>(id).Property = value;
//rolling back
}
using(var ts = new TransactionScope())
using(var session = factory.OpenSession())
{
var property = session.Get<Entity>(id).Property;
Assert.That(property).Does.Not.Equal(value);
}
On Jan 15, 1:17 pm, HH <[email protected]> wrote:
> Hi Fabio,
>
> I don't want to sound rude, but I know that the get is comming from
> the cache. I am not sure what you are trying to say, but isn't it
> strange that NHibernate returns data from a cache based on a
> transaction which was rollbacked? Or should I manage the NHibernate
> cache by calling Clear() on the ISession?
>
> I find it very hard to find out to which extend NHibernate supports
> working with TS and where I should manage things myself.
>
> Henk
>
> On 15 jan, 18:35, Fabio Maulo <[email protected]> wrote:
>
> > 2010/1/15 HH <[email protected]>
>
> > > -- statement #7
> > > begin transaction with isolation level: Unspecified
>
> > > -- statement #8
> > > commit transaction
>
> > > No select between statment #7 and #8.
>
> > Now you know why your test is not working.
> > In the second session.Get NH will Get the instance from session-cache and
> > not from DB.
>
> > --
> > Fabio Maulo
--
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.