-->
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: needs sample code and step by step instructions for caching
PostPosted: Wed Aug 09, 2006 3:44 am 
Newbie

Joined: Fri Aug 04, 2006 7:18 am
Posts: 2
Location: Chennai


Dear All,

I need how to do caching using ehacahe.

Step by step instructions for cache using ehcache[/b][/quote]

_________________
New to Hibernate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 3:59 am 
Newbie

Joined: Wed Jun 15, 2005 9:18 am
Posts: 11
Hello,

1. Download ehcache.jar and put it in your classpath

2. In hibernate.cfg.xml, declare ehcache as your cache provider using the hibernate.cache.provider_class property (hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider). If you use spring, set the property in the 'hibernateProperties' of the session factory declaration.

3. In your hbm file, declare caching as follow :

<class
name="eg.MyClass"
table="MY_TABLE"
mutable="false"
>
<cache usage="read-only" />
.....
</class>

or

<class
name="eg.MyClass"
table="MY_TABLE"
>
<cache usage="read-write" />
.....
</class>

4. Create ehcache.xml in your classpath and write some cache region :

<ehcache>
<diskStore path="java.io.tmpdir"/>

<defaultCache
maxElementsInMemory="0"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="0"
memoryStoreEvictionPolicy="LFU"
/>

<cache name="eg.MyClass"
maxElementsInMemory="25"
eternal="false"
timeToIdleSeconds="86400"
timeToLiveSeconds="86400"
overflowToDisk="false"
memoryStoreEvictionPolicy="LFU"
/>
</ehcache>

5. In your log4j.xml, set the log level for ehcache :

<logger name="org.hibernate.cache" additivity="true">
<level value="info" />
</logger>

<logger name="net.sf.ehcache" additivity="true">
<level value="info" />
</logger>

Hope this helps !


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.