-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to confire EhCahe.xml
PostPosted: Mon Nov 12, 2007 2:02 am 
Newbie

Joined: Thu Sep 06, 2007 3:45 am
Posts: 4
Hi All,

I am using Spring 2.0 and hibernate 3.1 in our project. In my project home page occupying the 6Mb size in 3 select queries. So I want place that 6Mb in cache with that i can reduce the database hits.

I knew that hibernate provides secondary level cache by using ehCache.xml.
I did the following:

1. Placed ehcache.xml in myproject.
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<cache name="com.sa.intranet.model.businessobject.SaPostingCategoryMaster"
maxElementsInMemory="50"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>

<!-- Sample cache named sampleCache2
This cache contains 1000 elements. Elements will always be held in memory.
They are not expired. -->
<cache name="com.sa.intranet.model.businessobject.SaPraisewallMaster"
maxElementsInMemory="50"
eternal="true"
overflowToDisk="false"
/>
2. In Both SaPraisewallMastern and SaPostingCategoryMaster hbm files, i placed
<cache usage="read-only"/>
3.
Configuration of in applicationConfig.xml
<prop key="hibernate.c3p0.use_sql_comment">true</prop>
<prop key="hibernate.c3p0.generate_statistics">
true
</prop>
<prop key="hibernate.cache.use_structured_entries">
true
</prop>

Thats it.
with the above configuration i am getting exception:

Code:
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
   at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:21)
   at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)
   ... 41 more



Can you help me how to follow preceding steps and how to test whether data is storing in cache or not

Regards,
Ravi Gonella


Top
 Profile  
 
 Post subject: How to configure EhCahe.xml
PostPosted: Mon Nov 19, 2007 2:44 am 
Newbie

Joined: Thu Sep 06, 2007 3:45 am
Posts: 4
Hi,

Can you please give me any updates on this.

Regards,
Ravi Gonella


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 11:51 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Ravi,
I have configured ehcache in my project recently. The exception message shows that you didn't configure the second level cache in hibernate configuration file-->hibernate.cfg.xml or hibernate.properties.

Inside the hibernate.cfg.cml add the following properties:


<!-- Enable/Disable the second-level cache -->
<property name="cache.use_second_level_cache">true</property>
<!-- cache implementation -->
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<!-- store the second-level cache entries in a more human-friendly format -->
<property name="cache.use_structured_entries">true</property>
<!-- enable/disable the query cache -->
<property name="cache.use_query_cache">false</property>
<!-- optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache) -->
<property name="cache.use_minimal_puts">true</property>

Or you can add the same properties in hibernate.properties file. Refer to hibernate.properties file given in etc folder of hibernate3.2 source distribution.


##########################
### Second-level Cache ###
##########################

## optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache)

#hibernate.cache.use_minimal_puts true


## set a prefix for cache region names

hibernate.cache.region_prefix hibernate.test


## disable the second-level cache

#hibernate.cache.use_second_level_cache false


## enable the query cache

#hibernate.cache.use_query_cache true


## store the second-level cache entries in a more human-friendly format

#hibernate.cache.use_structured_entries true


## choose a cache implementation

#hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProvider
hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.OSCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.SwarmCacheProvider


## choose a custom query cache implementation

#hibernate.cache.query_cache_factory

I hope this clears your exception.

Thanks
Shyam


Top
 Profile  
 
 Post subject: How to configure Hibernate Secondary Caching
PostPosted: Wed Nov 28, 2007 8:38 am 
Newbie

Joined: Thu Sep 06, 2007 3:45 am
Posts: 4
Hi,

Great Help..

I will try as you mension above...

Can you tell me how to check/test that result of querie are stored the cache.

As far as my knowledge need to check temp folder in my Tomcat.

Thanks once again,

Regards,
Ravi Gonella


Top
 Profile  
 
 Post subject: How to configure Hibernate Secondary Caching
PostPosted: Wed Nov 28, 2007 8:39 am 
Newbie

Joined: Thu Sep 06, 2007 3:45 am
Posts: 4
Hi,

Great Help..

I will try as you mension above...

Can you tell me how to check/test that result of querie are stored the cache.

As far as my knowledge need to check temp folder in my Tomcat.

Thanks once again,

Regards,
Ravi Gonella


Top
 Profile  
 
 Post subject: to see cache activity (hits, misses, puts)...
PostPosted: Wed Nov 28, 2007 10:13 am 
Newbie

Joined: Mon Oct 15, 2007 12:36 pm
Posts: 5
add this to your log4j configuration:

<logger name="org.hibernate.cache">
<level value="DEBUG"/>
</logger>

This will probably give you more detail than you need, but look for "cache miss" and "cache hit". You can tune it to focus on the type of cache you are using - in my case, my cache-usage is transactional:

<logger name="org.hibernate.cache.TransactionalCache">
<level value="DEBUG"/>
</logger>

hth,
Carl


Top
 Profile  
 
 Post subject: Re: to see cache activity (hits, misses, puts)...
PostPosted: Wed Nov 28, 2007 11:25 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Ravi,

Using Statistics and SecondLevelCacheStatistics you can read the cache entries and other details - no of hits, puts.

I use the following code to read my sessoin and second level cache details:


Statistics _stats = factory.getStatistics();
System.out.println("_stats: "+_stats);
SecondLevelCacheStatistics _sstats = _stats.getSecondLevelCacheStatistics("com.shyam.hibernate.Person");
System.out.println("_sstats: "+_sstats);
System.out.println("_sstats: "+_sstats.getCategoryName());
System.out.println("_sstats entries: "+_sstats.getEntries());

Thanks
Shyam


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