As for now, hibernate uses it's own instance of TreeCache (created by TreeCacheProvider). I am using TreeCache as JMX component in JBoss and I'd like to make hibernate using shared TreeCache instance outside Hibernate itself.
What I did is just make my own version of net.sf.hibernate.cache.TreeCache, say, MyTreeCache where changed consructor code as following:
Code:
private static TreeCacheMBean cache;
public TreeCache(String regionName, Properties props) throws CacheException {
this.regionName = '/' + regionName.replace('.', '/');
try {
synchronized (TreeCache.class) {
if (cache == null) {
cache = getCacheMBean();
}
}
} catch (Exception e) {
log.error("Error creating TreeCache.", e);
throw new CacheException(e);
}
}
public void destroy() throws CacheException {
// cache.destroy(); no need to destroy anymore.
}
Also I created version of TreeCacheProveder which instantiates MyTreeCache instead of TreeCache and put
<attribute name="CacheProviderClass">...MyTreeCacheProvider</attribute>
in hibernate-service.xml.
For me it seems to work perfect although I read somewhere in forum that for some reason TreeCache instance must be inside hibernate.
My question is: are there known issues with that configuration and if there are not, isn't it better way in light of Jboss-Hibernate integration? I mean configuring hibernate with just reference to external TreeCache MBean?