-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate 2nd level cache
PostPosted: Mon Jun 28, 2010 4:54 am 
Newbie

Joined: Mon Jun 28, 2010 4:46 am
Posts: 2
Im currently trying to get hibernate working using the caching provider that comes with hibernate.

net.sf.ehcache.hibernate.SingletonEhCacheProvider

I have a default cache and a class specific cache enabled in the ecache.xml which is referenced in my hibernate.cfg.xml file.
The class/mapping file specific cache is defined to handle upto 20000 objects.

However, I'm seeing no perfrormance gains since I turned on the cache mapping on one of the mapping files Im testing this with.

My test is as follows.

Load 10000 objects of the particular mapping file im testing (this should hit the DB and be a bottle kneck).
Next I go to load the same 10000 objects, as this point I would expect the cache to be hit and to see significant performance gains.

Have tried using both "read-only" and "read-write" cache mapping on the hibernate xml file.


I'm wondering is their anything I need to be doing to ensure the cache is being hit before the DB when loading objects?

Note as part of the test im pagin through these 10000 records using something similar to below ( paging a 1000 records at time).

Criteria crit = HibernateUtil.getSession() .createCriteria( persistentClass );
crit.setFirstResult(startIndex);
crit.setFetchSize(fetchSize);
return crit.list();

Any ideas on how i can verify if the cache is being used ? Or is there even a way i can check if the cache is defiently being populalated

Have seen that criteria has a caching mode setter ( setCacheMode() ) so is there something I should be doing with that??

I notice using the below stats code that theres 10000 objects in memory but
for some reason I'm getting 0 hits and more worryingly a huge number of misses (well over 20K).

Any ideas on what im doing worng? I take it the fact im getting misses is good as it means the cache is being used, but i cant figure out
why im not getting any cache hits. Is it down to the fact im using setFirstResult() and setFetchSize() with criteria.



System.out.println("Cache Misses = " + stats.getSecondLevelCacheMissCount());
System.out.println("Cache Hits Count = " + stats.getSecondLevelCacheHitCount());
System.out.println("2nd level elements in mem "+ stats.getSecondLevelCacheStatistics("com.someObject").getElementCountInMemory());


Top
 Profile  
 
 Post subject: Re: Hibernate 2nd level cache
PostPosted: Tue Jun 29, 2010 3:24 am 
Newbie

Joined: Mon Jun 28, 2010 4:46 am
Posts: 2
Anyone got any ideas on what Im doing wrong? Been stuck on this for a good few days now


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

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.