• No replies
18 Posts

Pinned topic Query Cache Not Working

‏2013-08-21T12:29:17Z |


I have implemented a plain L2 cache without query cache for Hibernate using wxs and its working fine. After adding the configurations to support query cache, data is not getting persisted in StandardQuerycache and UpdateTimestampsCache. 

In my application i am doing a searchByName operation. Whenever i do a searchByName operation, hibernate query is executed for every call. But this is not the case for searchById operation. In that query gets fired first and result object goes in cache.For next subsequent calls of searchById, data is returned from cache only.

My understanding is that, whenever i do a searchByName operation, List of objects will be returned. Main cache will hold all the result object. StandardQueryCache will contain key as sql executed along with query parameters.UpdateTimestampsCache should contain the timestamp of query executed. And then after the first search operatio, whenever i do a seach operation using same search criteria, all data should be returned from cache and no database call should be made.

Below are my configurations

A - Client side configuration

- Customer Entity

@Table(name="CUSTOMERS" )
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Customer implements Serializable {

- jpa properties

            <prop key="hibernate.cache.provider_class"></prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="objectgrid.configuration">ObjectGridName=Grid,ObjectGridType=REMOTE</prop> 

- I have put all wsobjectgrid.jar,wxshibernate.jar in shared library. I am using a standalone version of WXS server. My application server is websphere 7

B - Server side configuration

- object grid.xml


    <objectGrid name="Grid" txTimeout="30">
      <backingMap name="Map1" copyMode="COPY_TO_BYTES" 
      nullValuesSupported="false" />
      <backingMap name="Map2" copyMode="COPY_TO_BYTES" 
      nullValuesSupported="false" />
      <backingMap name="domain.Customer"  
readOnly="false" copyKey="false" 
                  lockStrategy="NONE" copyMode="COPY_TO_BYTES"/>
 <backingMap name="org.hibernate.cache.StandardQueryCache" 
readOnly="false" copyKey="false" 
                  lockStrategy="NONE" copyMode="COPY_TO_BYTES"/>
      <backingMap name="org.hibernate.cache.UpdateTimestampsCache"
readOnly="false" copyKey="false" 
                  lockStrategy="NONE" copyMode="COPY_TO_BYTES"/>
      <backingMap name="defaultCacheMap" readOnly="false" copyKey="false" 
                  lockStrategy="NONE" copyMode="COPY_TO_BYTES"/>            

- deployment.xml

    <objectgridDeployment objectgridName="Grid">
        <mapSet name="mapSet" numberOfPartitions="13" minSyncReplicas="0" maxSyncReplicas="1" >
            <map ref="Map1"/>
            <map ref="Map2"/>
            <map ref="domain.Customer"/>
            <map ref="org.hibernate.cache.StandardQueryCache" />
      <map ref="org.hibernate.cache.UpdateTimestampsCache" />
<map ref="defaultCacheMap" />