Second-level cache is enabled in a class, but no cache provider was selected. Fake cache used.

735 views
Skip to first unread message

Antonio Terreno

unread,
Sep 22, 2009, 4:28:13 AM9/22/09
to nhc...@googlegroups.com
Hi all,
I'm getting this message even if I'm pretty sure I've followed the "manual" on how to enable the 2nd level cache on our application.

On our hibernate.xml I've set up the cache as it follows:

  <object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate21" singleton="true">
    <property name="DbProvider" ref="DbProvider" />
    <property name="MappingAssemblies">
      <list>
        <value>XXX.BusinessDomain</value>
      </list>
    </property>
    <property name="HibernateProperties">
      <dictionary>
        <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
        <entry key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
        <entry key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/>
        <entry key="hbm2ddl.keywords" value="none"/>
        <entry key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>
        <entry key="hibernate.cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache" />
        <entry key="cache.use_second_level_cache" value="true" />       
        <entry key="expiration" value="300" /> <!-- five minutes, at the minute -->
      </dictionary>
    </property>
    <property name="ExposeTransactionAwareSessionFactory" value="true" />
  </object>


On our web.config as it follows:

  </configSections>
...
    <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler, NHibernate.Caches.SysCache" requirePermission="false" />
  </configSections>
 
  <syscache>
    <cache region="entities" expiration="3600" priority="5" />
    <cache region="LongTerm" expiration="3600" priority="5" /> <!-- as a reference -->
    <cache region="ShortTerm" expiration="900" priority="3" /> <!-- as a reference -->
  </syscache>

On the entities that I want to cache:

    <class name="XXX">
    <cache usage="nonstrict-read-write" region="entities" />


If you guys think that this is good we might have a problem elsewhere (no idea where, perhaps templating config files..)


Thanks for your patience and help.

toni
 
--
http://www.the-arm.com

Ayende Rahien

unread,
Sep 22, 2009, 5:22:14 AM9/22/09
to nhc...@googlegroups.com
Drop the hibernate prefix

Antonio Terreno

unread,
Sep 22, 2009, 9:37:33 AM9/22/09
to nhc...@googlegroups.com
Thanks, I've actually found that there was some duplication between the Web.Config and the hibernate.xml (spring) file.

Another question: does SysCache work with MySql DB or it works only with MS SQL Server?

On the doc I see:

SysCache2 requires Microsoft SQL Server 2000 or higher and .NET Framework version 2.0 or higher.



We are planning to use MS SQL Server, but at the moment on the query logs of mysql I can still see the queries performed each time, even on simple select from where id=?

Thanks again.
toni
--
http://www.the-arm.com

Scott White

unread,
Sep 22, 2009, 10:44:29 AM9/22/09
to nhc...@googlegroups.com
FYI, if you're already using Spring as your IoC then you can use Spring as your ProxyFactory:

        <entry key="proxyfactory.factory_class" value="Spring.Data.NHibernate.Bytecode.ProxyFactoryFactory, Spring.Data.NHibernate21" />

This has allowed me to drop two assemblies as my reference (Castle) since using NHib 2.1

-Scott

Ayende Rahien

unread,
Sep 22, 2009, 11:09:35 AM9/22/09
to nhc...@googlegroups.com
Antonio,
There is no relation to the database backend in SysCache

SysCache2 (stupid name) have dependencies on SQL Server, but not SysCache

Bill Pierce

unread,
Sep 22, 2009, 11:17:19 AM9/22/09
to nhc...@googlegroups.com
Should have named it SysCacheEx ;)

Antonio Terreno

unread,
Sep 22, 2009, 12:45:14 PM9/22/09
to nhc...@googlegroups.com
I've changed few criteria queries setting .SetCacheble(true) and now everything makes sense.

Another impression is that hibernate can't cache formulas (we have few count done with formulas on a couple of entities), am I wrong?

Thanks for your help.
--
http://www.the-arm.com

Ayende Rahien

unread,
Sep 22, 2009, 12:49:46 PM9/22/09
to nhc...@googlegroups.com
Antonio,
It most certainly should be able to cache formulas. Do you have an example where it doesn't?

Antonio Terreno

unread,
Sep 22, 2009, 4:23:30 PM9/22/09
to nhc...@googlegroups.com
I was wrong, one of our devs set cacheble to false on the queries, so all the counts I've noticed on the mysql logs were actually from that service.

Thanks.
--
http://www.the-arm.com
Reply all
Reply to author
Forward
0 new messages