I am using SysCache2 and NHibernate 2.1.2.4.
No matter how hard I try, NHibernate keeps loading previous instances of an entity.
My class is mapped as cacheable ReadWrite.
The cache region is the default, i.e. the full name of the class’s types.
I am performing all actions within a transaction.
The database is definitely being updated, and when I manually clear ASP .NET’s cache, the problem goes away.
I am doing a simple update, like this:
using(var transaction = NHSession.BeginTransaction())
{
var foo = Session.Load<Foo>(_fooId);
foo.Name = "A new name";
transaction.Commit();
}
Then I reload the entity later on (in a different session within the application), like this:
using(var transaction = NHSession.BeginTransaction())
{
var foo = Session.Load<Foo>(_fooId);
Response.Write(foo.Name);
transaction.Commit();
}
… but Foo’s name is still the old name, not the new name I just updated it to!
I worked this one out – for certain reasons I had two Session Factories. I didn’t realise that the Save operation was occurring within one factory, and the load was occurring in the other.