-->
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: refresh/reset EHCache regions
PostPosted: Tue Apr 18, 2006 8:55 am 
Newbie

Joined: Wed Jun 08, 2005 1:18 pm
Posts: 7
Location: China
Hi,

I'd like to be able to refresh/reset all EHCache regions without having to restart Hibernate and the webapp, it that possible ? (Hibernate v3, EHCache as integrated v1.1)

Regards,

Phil


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 10:17 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Get a hold to a EHCacheManager (I believe it is a singleton instance inside VM).
Or you can do that through SessionFactory - if EHCache is your Hibernate cache impl.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 7:06 am 
Newbie

Joined: Wed Jun 08, 2005 1:18 pm
Posts: 7
Location: China
Thanks,

Can you or somebody tell me more (not that i'm lazy, i have poor java knowledge)

- EHCache is my Hibernate cache impl as in the default hibernate 3.1. package.
- I see org.hibernate.cache.EhCache has a method clear()
- Idon't see how i can point to the cache from SessionFactory
- I can get Instance of singleton net.sf.ehcache.CacheManager
CacheManager cacheManager = CacheManager.getInstance();
Cache cache = cacheManager.getCache("name");
then it is not a org.hibernate.cache.EhCache but net.sf.ehcache,
it seems the wrong class, so i think i'm going the wrong way...

Regards,
Phil


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 7:15 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
Idon't see how i can point to the cache from SessionFactory

See Hibernate API - SessionFactory.evict*

Quote:
Cache cache = cacheManager.getCache("name");
then it is not a org.hibernate.cache.EhCache but net.sf.ehcache,
it seems the wrong class, so i think i'm going the wrong way...


Hibernate just wraps around this one - this is the actual object that holds your cached entities.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 12:06 pm 
Newbie

Joined: Wed Jun 08, 2005 1:18 pm
Posts: 7
Location: China
Thanks a lot alesg,

It works. Just want to post the code here in case it could help people:
try {
org.hibernate.cache.EhCache ehcache = null;
Cache cache = cacheManager.getCache("region");
org.hibernate.cache.EhCache ehcache = new org.hibernate.cache.EhCache(cache);
ehcache.clear();
} catch (CacheException ce) {}
}finally {}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 3:12 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
If you want to refresh your Hibernate pojos, better use SessionFactory.evict* - cache independent.


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.