-->
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.  [ 4 posts ] 
Author Message
 Post subject: Query cache expires prematurely
PostPosted: Tue Jun 01, 2010 1:32 pm 
Newbie

Joined: Mon Mar 05, 2007 5:12 pm
Posts: 3
Hello,

our hotel reservation system is using the L2 cache with the query cache. The issue I'm seeing is that it seems that after the cache size of the HotelImpl domain object is reached, but below the maximum in memory, either the query cache or L2 cache seems to partially expire.

Below are the settings we're using.

Hibernate via Spring configuration:
Code:
...
   <bean id="eclSessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref local="dataSource" />
      </property>

      <property name="mappingResources">
         <list>
            <value>hibernate/mapping/ARRatePlan.hbm.xml</value>
            <value>hibernate/mapping/Delivery.hbm.xml</value>
            <value>hibernate/mapping/ECLUser.hbm.xml</value>
            <value>hibernate/mapping/Namespace.hbm.xml</value>
            <value>hibernate/mapping/IPAddress.hbm.xml</value>
            <value>hibernate/mapping/UserAgent.hbm.xml</value>
            <value>hibernate/mapping/ECLError.hbm.xml</value>
            <value>hibernate/mapping/ECLWarning.hbm.xml</value>
            <value>hibernate/mapping/Hotel.hbm.xml</value>
            <value>hibernate/mapping/RoomType.hbm.xml</value>
            <value>hibernate/mapping/RatePlan.hbm.xml</value>
            <value>hibernate/mapping/Rate.hbm.xml</value>
            <value>hibernate/mapping/PerDayRate.hbm.xml</value>
            <value>hibernate/mapping/Phone.hbm.xml</value>
            <value>hibernate/mapping/RewardProgram.hbm.xml</value>
            <value>hibernate/mapping/SpecialRequest.hbm.xml</value>
            <value>hibernate/mapping/BNType.hbm.xml</value>
            <value>hibernate/mapping/Currency.hbm.xml</value>
            <value>hibernate/mapping/ARRoomType.hbm.xml</value>
            <value>hibernate/mapping/Inventory.hbm.xml</value>
            <value>hibernate/mapping/ICPRLog.hbm.xml</value>
            <value>hibernate/mapping/ICPRLogType.hbm.xml</value>
            <value>hibernate/mapping/Restrictions.hbm.xml</value>
            <value>hibernate/mapping/Source.hbm.xml</value>
            <value>hibernate/mapping/State.hbm.xml</value>
            <value>hibernate/mapping/CryptoState.hbm.xml</value>
            <value>hibernate/mapping/Status.hbm.xml</value>
            <value>hibernate/mapping/UserLock.hbm.xml</value>
            <value>hibernate/mapping/Silo.hbm.xml</value>
            <value>hibernate/mapping/ConfirmationNumber.hbm.xml</value>
            <value>hibernate/mapping/queries.hbm.xml</value>
            <value>hibernate/mapping/AddressCity.hbm.xml</value>
            <value>hibernate/mapping/AddressCountry.hbm.xml</value>
            <value>hibernate/mapping/AddressStateProv.hbm.xml</value>
            <value>hibernate/mapping/CardCode.hbm.xml</value>
            <value>hibernate/mapping/CardNumber.hbm.xml</value>
            <value>hibernate/mapping/CardType.hbm.xml</value>
            <value>hibernate/mapping/PaymentCard.hbm.xml</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.SQLServerDialect
            </prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
         </props>
      </property>
...


Ehcache:
Code:
<ehcache>
   <diskStore path="java.io.tmpdir" />
   <defaultCache maxElementsInMemory="10000" eternal="true" overflowToDisk="false" timeToIdleSeconds="1800" timeToLiveSeconds="0" diskPersistent="false" diskExpiryThreadIntervalSeconds="1200" />
   
   <!-- Nomad entities -->
   <cache name="com.newtrade.nomad.domain.Adaptor" maxElementsInMemory="15" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.Authentication" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.DeliveryGroup" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.DeliveryType" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.Interface" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false"/>
   <cache name="com.newtrade.nomad.domain.Partner" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.PartnerRole" maxElementsInMemory="15" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.PartnerType" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.PartnerTypeRule" maxElementsInMemory="15" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.PayloadType" maxElementsInMemory="15" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.Route" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.RouteStatus" maxElementsInMemory="5" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.ServicePoint" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.DeliveryGroup.deliveryTypes" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.PartnerRole.authenticationList" maxElementsInMemory="20" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.Partner.roles" maxElementsInMemory="20" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.Relationship" maxElementsInMemory="5" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.nomad.domain.FaultStrategy" maxElementsInMemory="5" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />

   <!-- EQC entities -->
   <cache name="com.newtrade.ecl.delivery.hibernate.BNTypeImpl" maxElementsInMemory="20" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.CurrencyImpl" maxElementsInMemory="40" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.ECLUserImpl" maxElementsInMemory="20000" eternal="true" timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.HotelImpl" maxElementsInMemory="20000" eternal="true" timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.IPAddressImpl" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.NamespaceImpl" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.SiloImpl" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.SourceImpl" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.StateImpl" maxElementsInMemory="20" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.CryptoStateImpl" maxElementsInMemory="20" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.StatusImpl" maxElementsInMemory="20" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.UserAgentImpl" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.RatePlanImpl" maxElementsInMemory="20000" eternal="true" timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.RoomTypeImpl" maxElementsInMemory="20000" eternal="true" timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.CardTypeImpl" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.CardCodeImpl" maxElementsInMemory="10" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
   <cache name="com.newtrade.ecl.delivery.hibernate.ICPRLogTypeImpl" maxElementsInMemory="5" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
</ehcache>


The Hibernate mapping for the HotelImpl domain object:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.newtrade.ecl.delivery.hibernate">
   <class name="HotelImpl" table="hbHotel">
      <cache usage="read-only" />
      <id name="hotelIID" column="HotelIID">
         <generator class="native" />
      </id>
      <property name="hotelId" column="HotelID"/>
   </class>
</hibernate-mapping>


The way the code query the DB is like the following:
Code:
   private Collection<HotelImpl> retrieveHotelList(final Collection<String> ids) {
      List<HotelImpl> hotelList = new ArrayList<HotelImpl>();

      for (String id : ids) {
         HotelImpl hotel = (HotelImpl) getHibernateHelper().findCachedSingleResult(
               "from HotelImpl where hotelId = ?", id);
         if (hotel != null) {
            hotelList.add(hotel);
         }

      }

      return hotelList;
   }

   public Object findCachedSingleResult(String queryStr, String memberValue) {
       List results = findCachedResults(queryStr, memberValue);
       if (results.size() > 0) {
          return results.get(0);
       } else {
          return null;
       }
   }
   
   public List findCachedResults(final String queryStr, final String memberValue) {
      return (List) m_template.execute(new HibernateCallback() {
         public Object doInHibernate(Session session) {
            Query query = session.createQuery(queryStr);
             query.setString(0, memberValue);
             query.setCacheable(true);
             query.setCacheMode(CacheMode.NORMAL);
             return query.list();
         }
      });
   }


The system uses the following APIs versions:
Hibernate: 3.2.4.sp1
Ehcache: 1.2.3
Spring: 2.0.6

Thanks for help.


Top
 Profile  
 
 Post subject: Re: Query cache expires prematurely
PostPosted: Mon Jun 07, 2010 3:24 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I can't tell you why the cache expires prematurely.
Anyway I suggest you to also set timeToIdleSeconds to zero if you want eternal caching for class Hotel.
Furthermore I suggest you to define the properties for the 2L Query-cache explicitely,
otherwise there's a fall-back to the default-cache :

Code:
<cache  name="org.hibernate.cache.StandardQueryCache"
            maxElementsInMemory="10000"
            eternal="true"
            timeToIdleSeconds="0"
            overflowToDisk="false"
            />


And finally it makes no sense to use the L2 query cache for lookup queries (= queries with the condition set on a primary key value) , because in this case you can use the L2 cache directly without enabling the query cache.
This by calling either
entityManager.find(...) or session.get(...) , depending on if you use classic or jpa approach.


Top
 Profile  
 
 Post subject: Re: Query cache expires prematurely
PostPosted: Mon Jun 07, 2010 9:06 am 
Newbie

Joined: Mon Mar 05, 2007 5:12 pm
Posts: 3
Thanks the answers.

I added the configuration for the StandardQueryCache and UpdateTimestampsCache and it solved the issue. Without these new configurations, hotel entities started to expire after 5000 cached objects. By the way, do I need to configure UpdateTimestampsCache?

Thanks for the advice about the way we query the DB. We could replace multiple access simply with the find(...) operation.

Jerome


Top
 Profile  
 
 Post subject: Re: Query cache expires prematurely
PostPosted: Mon Jun 14, 2010 2:40 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
By the way, do I need to configure UpdateTimestampsCache?


If you use the 2L query-cache, yes, then it is very important to configure UpdateTimestampsCache in a way
that their values are cached eternally.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.