-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate second level caching
PostPosted: Thu May 12, 2011 1:33 am 
Newbie

Joined: Wed May 11, 2011 3:06 am
Posts: 2
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.