Hibernate version: 3.2.0
Ehcache version: 1.2.4
Spring version: 2.0.3
I'm having issues with getting the "caching" behaviour to work. I've just mapped a simple Country business object to my country table in the database and enabled ehcache to cache on this particular table. However, when i load up my page that calls the function to get all countries, there does not seem to be any performance increase after the first hit like i would expect. The outputted log times are as follows (according to the code i've pasted below).
****** Get Country List exec time: 2590ms -- 236 items ******
****** Get Country List exec time: 2109ms -- 236 items ******
****** Get Country List exec time: 2344ms -- 236 items ******
****** Get Country List exec time: 2032ms -- 236 items ******
When i start up my Resin, the logs show that my ehcache provider is enabled, and i see the log message "- read-only cache configured for mutable class: com.gdi.core.businessobjects.Country" so i would assume my Country should be returning from cache after first hit. Is there anything i'm missing or should be doing differently? I've posted details of my current setup including the source code that is getting the country list below.
Also, is there anywhere i can dig into the SessionFactory... or ehcache manager for statistics during each call? I'd like to somehow know if the system is actually caching or not caching the results. I'm just assuming it's not caching based on the response time between each calls on such a simple query. Most examples i've seen calls that take 1800 ms reduced down to 50-100 ms so i'm expecting a level of improvement in performance around this factor in my application as well.
Country Business Object hbm.xml mapping
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"> <!-- Generated 10-Aug-2006 12:24:19 PM by Hibernate Tools 3.2.0.beta6a --> <hibernate-mapping> <class name="com.gdi.core.businessobjects.Country" table="country"> <id name="id" type="int"> <column name="id" /> <generator class="sequence"> <param name="sequence">country_id_seq</param> </generator> </id> <property name="name" type="string"> <column name="name" length="32" not-null="true" /> </property> <property name="code" type="string"> <column name="code" length="5" not-null="true" /> </property> <property name="numericCode" type="string"> <column name="numericcode" length="3" not-null="true" /> </property> <property name="alphaCode" type="string"> <column name="alphacode" length="3" not-null="true" /> </property> </class> </hibernate-mapping>
in my spring/hibernate configuration session factory definition
Code in my DAO which extends HibernateDaoSupportCode:<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.generate_statistics">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">gdi-ehcache.xml</prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property> <property name="entityCacheStrategies"> <props> <prop key="com.gdi.core.businessobjects.Licensee">read-only</prop> <prop key="com.gdi.core.businessobjects.Country">read-only</prop> <prop key="com.gdi.core.businessobjects.CountryRegion">read-only</prop> </props> </property>
EhCache definition:Code:return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { long startTime = System.currentTimeMillis(); Query query = session.createQuery("from Country order by name asc"); List list = query.list(); long endTime = System.currentTimeMillis(); System.out.println("****** Get Country List exec time: " + (endTime - startTime) + "ms -- " + list.size() + " items ******" ); return list; } } );
Name and version of the database: PostGres 7.4Code:<ehcache> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"/> <cache name="com.gdi.core.businessobjects.Licensee" maxElementsInMemory="500" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"/> <cache name="com.gdi.core.businessobjects.Country" maxElementsInMemory="300" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"/> <cache name="com.gdi.core.businessobjects.CountryRegion" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"/> </ehcache>
Debug level Hibernate log excerpt:
- Second-level cache: enabled
- Query cache: enabled
- Cache provider: org.hibernate.cache.EhCacheProvider
- Optimize cache for minimal puts: disabled
- Structured second-level cache entries: disabled
- Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
- Statistics: enabled
- Deleted entity synthetic identifier rollback: disabled
- Default entity-mode: pojo
- building session factory
- read-only cache configured for mutable class: com.gdi.core.businessobjects.Licensee
- read-only cache configured for mutable class: com.gdi.core.businessobjects.CountryRegion
- read-only cache configured for mutable class: com.gdi.core.businessobjects.Country
- Not binding factory to JNDI, no JNDI name configured
- starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
- Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
- starting query cache at region: org.hibernate.cache.StandardQueryCache
- Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.


Reply With Quote
