I'm using hibernate 3.0.4 and spring 1.2.1. I'm doing a very simple proof of concept to learn hibernate. I have a table consisting of 3 columns: id, city and zipcode. the query is given the city, i want the zipcodes. I want to use the 2nd level cache to prevent a db hit for each request. everything seems to be working except the caching.
For a local db with spring, hibernate + ehcache:
1st request: ~700ms, 2nd request 40ms, 3rd request 30ms, 4th request 180ms.
Using spring's jdbc functionality, i get repsonse times along the lines of 1: ~700ms, 2: 0ms, 3: 0ms....
jdbc is working much faster. i would think if the cache was being accessed then i would have similar performance.
what are the requirements that need to be fulfilled to utilize the 2nd level cache?
here are some excerpts from my log & config files:
not sure what i am missing. i would think there would be some message stating it was accessing the cache.
Second-level cache: enabled
Query cache: disabled
Cache provider: org.hibernate.cache.EhCacheProvider
Optimize cache for minimal puts: disabled
Structured second-level cache entries: disabled
com.mytest.model.CityZip Cache: Using SpoolingLinkedHashMap implementation
initialized MemoryStore for com.mytest.model.CityZip
Initialised cache: com.mytest.model.CityZip
instantiating cache region: com.mytest.model.CityZip usage strategy: read-only
read-only cache configured for mutable class: com.mytest.model.CityZip
result row: EntityKey[com.mytest.model.CityZip#66]
Initializing object from ResultSet: [com.mytest.model.CityZip#66]
Hydrating entity: [com.mytest.model.CityZip#66]
total objects hydrated: 19
resolving associations for [com.mytest.model.CityZip#35]
adding entity to second-level cache: [com.mytest.model.CityZip#35]
done materializing entity [com.mytest.model.CityZip#35]
my class com.mytest.model.CityZip has the equals and hashcode methods overridden
inside my dao which extends HibernateDaoSupport:
ehcache xml file has:
List tmp = getHibernateTemplate().find(query, city);
hibernate xml file has:
<class name="com.mytest.model.CityZipZip" table="cityzip">
<id name="id" column="cityzip_id">
<property name="zipcode" column="zipcode"/>
<property name="city" column="city"/>