These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Can't seem to get my collections to cache correctly
PostPosted: Wed Aug 09, 2006 1:09 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I have activated the 2nd level cache in my domain with the following configuration:

Code:
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.0" >
  <session-factory name="MyApp">

    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">connection string is here!</property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <property name="hibernate.cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
    <property name="relativeExpiration">300</property>
    <property name="cache.use_query_cache">true</property>

    <!-- Mapping files -->
    <mapping assembly="MyDomain" />

  </session-factory>
</hibernate-configuration>


I have also added <cache> elements to all of my domain objects and to the collections. Example mapping:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
   <class name="MyDomain.Parent, MyDomain" table="Parent">

    <cache usage="read-write"/>

    <id name="ID" type="Int32" column="ID">
         <generator class="identity"/>
      </id>

    <set name="Children" table="Child" inverse="true" lazy="true" cascade="all-delete-orphan">
      <cache usage="read-write"/>
      <key column="ParentID"/>
         <one-to-many class="MyDomain.Child, MyDomain"/>
      </set>

...

    </class>

</hibernate>


However, when I watch the DB activity in SQL Server profiler, I am still seeing hits on the DB to load the collections when I access the Parent.Children property.

Must be missing something real basic but I can't seem to find it.

Any ideas?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 4:18 am 
Newbie

Joined: Tue Aug 08, 2006 8:45 pm
Posts: 3
you also need to configure syscache, see section 20.3 of the the online manual

Code:
<configuration>
    <configSections>
        <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache"/>
    </configSections>
    <syscache>
        <cache relativeExpiration="500" priority="4"/>
    </syscache>
</configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 4:50 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hmmm...I thought I only needed to add config entries for <syscache> if I wanted to specifically control the caching for individual cache regions....at least that is how I interepetted the doco!

Caching is currently working without any <syscache> config entries for the Parent but not for any of my collections. Do I need to configure each of the collection cache regions manually then? If so, what would be the exact region name for the Parent.Children collection because I have tried a few variations and none seem to work.

I also tried adding the exact example you provided (without a cache region) and it didn't work either.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 12:21 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
do you have the "MyDomain.Child" class set to use the cache? you would need:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
   <class name="MyDomain.Child, MyDomain" table="Child">

    <cache usage="read-write"/>

    <id name="ID" type="Int32" column="ID">
         <generator class="identity"/>
    </id>

    ...
  </class>
</hibernate-mapping>


without setting the cache element on the child class, the Parent.Child collection, as it is in the cache, is just a collection of references (identifiers) to the actual objects. therefore, when you actually iterate() over the colleciton, you would see db activity to actually load the Child object.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 1:09 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Oh man...can't believe I missed that one! You are right that the cache element was missing from the child entity...I thought I had checked all of those!!

Thanks Devon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.