Distributed Transaction rollback and L2 cache

9 views
Skip to first unread message

Andy O

unread,
Feb 9, 2012, 12:27:50 PM2/9/12
to nhusers
I think I might be going a bit insane staring at this for a while, so
coming here to get set straight. Here's what I'm seeing:

When NHibernate participates in a distributed transaction (eg
TransactionScope) and the NHibernate transaction commits, but the
TransactionScope rolls back, the 2nd level cache gets out of sync (it
has cached the data from the NHibernate transaction). Is this
expected? Is there a way to configure NHibernate to get around this?
If it's expected, that's fine, I can just deal w/ it rather than
trying to force it to work.

Here's a bit of a contrived example but hopefully makes the point:
using (var scope = new TransactionScope()
{
using (var session = NHibernateSessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var thing = session.Get<Thing>(id);
thing.Prop = true;
transaction.Commit();
}
// no scope.Complete so will rollback
}

using (var session = NHibernateSessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var thing = session.Get<Thing>(id);
Assert.IsFalse(thing.Prop); // <-- Prop is true!
}

Thanks
Reply all
Reply to author
Forward
0 new messages