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.