Hi,
I had the impression that changing a natural id property of an entity
would not invalidate its second level cache entry, however, a simple
test showed me it isn't so: it does get invalidated.
My reference was a post by Ayende:
http://ayende.com/blog/4061/nhibernate-natural-id.
Has this behavior changed or is it a bug?
BTW, my test is this:
protected void BeforeMapClass(IModelInspector modelInspector, Type
type, IClassAttributesMapper classCustomizer)
{
classCustomizer.Cache(x => x.Usage(CacheUsage.NonstrictReadWrite));
...
}
mapper.Class<Customer>(ca =>
{
ca.NaturalId(x => x.Property(c => c.Name), x => x.Mutable(true));
...
}
using (ISession session = factory.OpenSession())
{
Customer c = session.Get<Customer>(CustomerId);
var loadCount = factory.Statistics.EntityLoadCount;
//1
var hitCount = factory.Statistics.SecondLevelCacheHitCount;
//0
c.Name = c.Name.Substring(0, c.Name.Length - 2);
session.Flush();
}
using (ISession session = factory.OpenSession())
{
Customer c = session.Get<Customer>(CustomerId);
var loadCount = factory.Statistics.EntityLoadCount;
//2
var hitCount = factory.Statistics.SecondLevelCacheHitCount;
//0
}
Is this the normal behavior? Perhaps it is related to the fact that
the natural id is set to mutable, it probably is the right thing to
do.
Thanks!
RP
--
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.