-
1. Sharing Infinispan Cache with multiple Hibernate SessionFactories
galder.zamarreno Feb 24, 2011 10:07 AM (in response to alexmak)1 of 1 people found this helpfulFirst of all, the JNDI region factory is so that multiple apps can benefit from a single cache manager, and hence a single JGroups channel. That way, if you have N apps, you don't need to maintain N cache managers and N JGroups channels, because for each JGroups channels you have to figure out different multicast address...etc.
However, what you seem to be trying is to have two separate Hibernate SessionFactories share the caches which is a different thing. I don't know how to do that and probably it's not a good idea, because each app could be deploying different versions of the same entities, even if the class names are the same.
I suspect that what you want is for different apps to share the same Hibernate session factory but you'd have to check with the Hibernate people on how to do that.
-
2. Re: Sharing Infinispan Cache with multiple Hibernate SessionFactories
alexmak Feb 25, 2011 9:04 AM (in response to galder.zamarreno)1 of 1 people found this helpfulGalder,
thanks for reply!
I have found the reason for such behavior. And it has nothing to do with Infinispan.
In fact it turned out to be the fundamental feature of app server – different classloaders for different applications.
Hibernate’s org.hibernate.cache.CacheKey.equals() method returns false for CacheKey classes loaded from different classloaders.
Moving all Hibernate jars to Jetty lib/ext folder and removing them from web applications have resolved the classloader limitation.
And now applications can share the entities the way I need.
By the way, I found next posible solutions so far:
- Moving all Hibernate libraries to application server classloader.
- Patching and replacement of original Hibernate's CacheKey class.
- Using Aspectj to create around advice over the equals method, and write classloader-agnostic implementation.