-->
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.  [ 6 posts ] 
Author Message
 Post subject: 2nd Level cache not working
PostPosted: Tue Sep 04, 2012 9:55 am 
Newbie

Joined: Tue Sep 04, 2012 9:07 am
Posts: 3
Hello,

I am using Hibernate 4.1.1-final with JPA 2.0.
I am trying to enable 2nd level caching using EHCACHE.

But cache is not working as I am able to see SQL statements getting generated twice if I execute the query twice.

We are delegating responsibility of opening and closing sessions to Hibernate.

Please find the configuration as below,

Persistence.xml ----

We have enabled 2nd level cache along with query cache

<properties>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/redemptionstageEntityManagerFactory"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.provider_configuration_file_resource_path" value="ehcache.xml" />

<!--<property name="hibernate.hbm2ddl.auto" value="update"/>
-->
</properties>

ehcache.xml in WEB-INF/classes----
<ehcache>
<diskStore path="E:\\ehcache\\"/>

<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="360000"
timeToLiveSeconds="360000"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="360000"
memoryStoreEvictionPolicy="LRU"
/>

<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="360000"
timeToLiveSeconds="360000"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="360000"
memoryStoreEvictionPolicy="LRU"
/>

<cache name="query.AdministrativeAreasPerCountry"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="180000"
timeToLiveSeconds="864000"
overflowToDisk="true"/>

<cache name="com.verifone.offers.entitiesCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<!--
diskSpoolBufferSizeMB="20"
transactionalMode="off" >-->

</cache>

</ehcache>

-------------------------------------------------------

We tried to put @Cachable (true) (javax.persistence.Cacheable) annotation in entity

We also tried to make query cacheable by tweaking the code as below ( as through JPA we cant do it),

Query query = em.createNamedQuery("Coupon_Information.findAll");
query.getResultList();


if(query instanceof QueryImpl) {
((QueryImpl)query).getHibernateQuery().setCacheable(true);
((QueryImpl)query).getHibernateQuery().setCacheRegion("com.verifone.offers.entitiesCache");
}


But still the entity is not cached although log states 2nd level cache and query cache is enabled.

Can someone guide to find the solution? An early reply will be highly appreciated as we have a tight dead line.


Thanks,
Abhay


Top
 Profile  
 
 Post subject: Re: 2nd Level cache not working
PostPosted: Tue Sep 04, 2012 10:54 am 
Newbie

Joined: Tue Sep 04, 2012 10:36 am
Posts: 3
Have you tried @org.hibernate.annotations.Cache annotation in entity?


Top
 Profile  
 
 Post subject: Re: 2nd Level cache not working
PostPosted: Tue Sep 04, 2012 12:09 pm 
Newbie

Joined: Tue Sep 04, 2012 9:07 am
Posts: 3
Hi,

I have tried @Cache annotation in entity, but it is still not working.
Any further clue?

Thanks,
Abhay


Top
 Profile  
 
 Post subject: Re: 2nd Level cache not working
PostPosted: Tue Sep 04, 2012 12:32 pm 
Newbie

Joined: Tue Sep 04, 2012 10:36 am
Posts: 3
I have the ehcache working in the following conditions:
1. Using only hibernate criteria api with list() method and setCachable(true)
2. ehcache.xml contains default cache only and is located in the classpath root:
Code:
  <defaultCache
            maxElementsInMemory="10000"
            eternal="true"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="false"
            diskSpoolBufferSizeMB="30"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="FIFO"
            statistics="false"
            />


Top
 Profile  
 
 Post subject: Re: 2nd Level cache not working
PostPosted: Fri Sep 07, 2012 5:44 am 
Newbie

Joined: Tue Sep 04, 2012 9:07 am
Posts: 3
Hello,

Tried out the defaultCache settings given by you.Nothing works ...
Looks like it is issue with JPA 2.0-Hibernate ....

Any clues from someone will be very much helpful


Thanks,
Abhay


Top
 Profile  
 
 Post subject: Re: 2nd Level cache not working
PostPosted: Thu Oct 25, 2012 6:00 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
I used the same factory as you, and running into the same frustration.

Here is a change that made the difference for me (depending on your configuration approach):

Code:
//      prop.put("hibernate.cache.region.factory_class","org.hibernate.cache.ehcache.EhCacheRegionFactory");
      prop.put("hibernate.cache.region.factory_class","org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory");


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.