-->
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+EhCache not working
PostPosted: Tue May 31, 2011 1:38 pm 
Newbie

Joined: Sat Dec 11, 2010 8:49 am
Posts: 19
Hello,

I am trying to enable second-level cache (Ehcache) in Hibernate but without success.

My Spring configuration is as follows:
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>

My ehcache.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="c:\cache\"/>
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />

In my entity classes i use
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class A implements java.io.Serializable {

I use Criteria API for loading data:
Criteria criteria = session.createCriteria(A.class.getName()).setFirstResult(offset * maxResults).setMaxResults(maxResults);
criteria.addOrder(Order.asc("id"));
criteria.setCacheable(true);
return criteria.list();

I checked cache statistics and in log i can see that:
session.getSessionFactory().getStatistics().getSecondLevelCacheHitCount() is always 0!
session.getSessionFactory().getStatistics().getSecondLevelCacheMissCount() is not 0 but varying and
session.getSessionFactory().getStatistics().getSecondLevelCachePutCount() is constantly increasing.

Also i checked .data files in "c:\cache" and all files are empty.

Can someone help me about this, what i am missing?

Best regards.


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.