Hi,
I am trying to use second level caching. EHCache
I have added the following in the config file
<property name="hibernate.cache.use_second_level_cache">true</property> <property name="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider</property> ... <class-cache class="com.hib.ABC" usage="read-only" /> ...
To the hbm file of table ABC:
<class name="ABC"> <cache usage="read-only"/> ....
I have also created an ehcache.xml file.
Now I am trying to check if caching is working
For that I am accessing the table in a loop
... setupHibernateConfig(); for(int i = 1; i <= 5; i++) { ABC abc= new ABC (); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria crit = s.createCriteria(ABC.class) List<ABC> temp = new ArrayList<ABC>(); temp = crit.list(); System.out.println(temp.size()); // no of rows in table s.close(); } ...
But I am not sure if the caching is working. I am printing the number of rows in the cached table. To check if the hit is on the cache and not database, I tried to halt the loop for some time. Meanwhile I inserted another row into database. If caching was working fine then this the row printed should be same and should not reflect the added row. But the count is increasing. What am I doing wrong?
|