So debugging into the eventual ISessionFactory instance confirms that
the ISessionFactory.IsSecondLevelCacheEnabled property is in fact
'true' and that the CacheProvider is set correctly.
But asking FNH to spit out my mappings to disk turns up that the
mappings for my entity don't seem to be created with the proper cache-
related attributes in the mapping (e.g., no <cache usage="read-only"/>
value).
This code....
class MyEntity: ClassMap<MyEntiity>
{
public MyEntityMap()
{
Map(x => x.Id);
Map(x => x.Width);
Map(x => x.Height);
Map(x => x.Name);
Cache.AsReadOnly();
}
}
...produces this XML mapping file...
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="">
<class name="MyEntity, MyAssembly, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" table="MyEntity" xmlns="urn:nhibernate-
mapping-2.2">
<id name="Id" type="Int64" column="id">
<generator class="identity" />
</id>
<property name="Width" type="Int32">
<column name="width" />
</property>
<property name="Height" type="Int32">
<column name="height" />
</property>
<property name="Name" type="String">
<column name="name" />
</property>
</class>
</hibernate-mapping>
...which is obviously devoid of any cache attribute at all, explaining
why I don't get ant caching on my entity. Am I overlooking something
here in the function of Cache.AsReadOnly() or is this a bug...?
Any help appreciated.
Thx in advance,
-Steve B.
On Jul 30, 4:06 pm, sbohlen <[email protected]> wrote:
> I must be overlooking something (probably simple), but can anyone
> describe to me (or point me to a blog post or other resource) that
> covers how to use FNH to configure the second-level-cache properly?
>
> In my configuration, I'm presently doing this...
>
> MsSqlConfiguration.MsSql2005.ConnectonString(...)
> .Cache(c=>c.ProviderClass<HashtableCacheProvider>());
>
> ...and in my ClassMap<T> I'm doing...
>
> Map(...)
> Cache.AsReadOnly();
>
> ...which would SEEM from the docs to be all that's needed. Using XML,
> I'd also have to set...
>
> <property name="cache.use_second_level_cache">true</property>
>
> ...in the hibernate.cfg.xml file but while I was somewhat expecting to
> be able to say something like...
>
> MsSqlConfiguration.MsSql2005.ConnectonString(...)
> .Cache(c=>c.ProviderClass<HashtableCacheProvider>())
> .Cache(x=x.UseSecondLevelCache(true)); //<--- expected line
> here
>
> ...there's no such method exposed for the Cache. In FNH, does simply
> setting the Cache's ProviderClass implicitly also ENABLE the second-
> level cache or am I missing another method that's needed to actually
> turn the Cache on? Didn't see anything that obvious in
> intellisense...
>
> And if nothing else is needed (e.g., my code above -- minus the extra
> method I seem to want to call even though it doesn't exist -- is
> actually correct), does anyone have any other ideas about why this
> collection of settings actually doesn't prevent my query for my cached
> objects from hitting the DB when its invoked a second time?
>
> Feels like this would take perhaps 20 seconds in XML but is becoming
> increasingly frustrating in code :(
>
> Thoughts, anyone--?
>
> -Steve B.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---