Hibernate version: 3.2.0
Ehcache version: 1.2.4
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: 2890ms -- 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. Thanks for any help
Mapping documents:
For country
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:
<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>
Code between sessionFactory.openSession() and session.close():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 you are using:
PostGres 7.4
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.