2 Replies Latest reply on Jan 9, 2013 3:15 PM by 983682

    Coherence as Hibernate L2 Cache

      Hi All,

      I'm looking to use Coherence to replicate my hibernate query cache and need some pointer if possible.

      The references on the Oracle website is out of date (last update 2010...hibernate3)..

      .here's the best that I've found online, cause I'm using hibernate4

      My major question is that the comments on

      says that it should only be used for testing....is there a class that provides this functionality that's production ready?
      or will I have to implement some like in the middlewaremagic article above?

      thanks in advance


      <bean id="sessionFactory"
      <property name="dataSource" ref="dataSource" />
      <property name="hibernateProperties">
      <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
      <prop key="hibernate.show_sql">false</prop>
      <prop key="hibernate.format_sql">false</prop>

      <prop key="hibernate.cache.use_query_cache">true</prop>
      <prop key="hibernate.cache.use_second_level_cache">true</prop>
      <!--<prop key="hibernate.cache.region.factory_class">cache.CoherenceRegionFactory</prop>-->
      <prop key="hibernate.cache.region.factory_class">org.hibernate.testing.cache.CachingRegionFactory</prop>
      <prop key="hibernate.cache.provider_class">com.tangosol.coherence.hibernate.CoherenceCacheProvider</prop>

      <prop key="hibernate.cache.generate_statistics">true</prop>
      <prop key="hibernate.generate_statistics">true</prop>
        • 1. Re: Coherence as Hibernate L2 Cache
          René van Wijk
          Note that org.hibernate.testing.cache.CachingRegionFactory is just a base example, in which you can put your specific cache API

          For example, the start and stop methods for the cache are still empty
               public void start(Settings settings, Properties properties) throws CacheException {
               public void stop() {
          The Hibernate distribution itself provides implementation for eh-cache (org.hibernate.cache.ehcache.EhCacheRegionFactory) and InfiniSpan (org.hibernate.cache.infinispan.InfinispanRegionFactory).

          From these examples you can build your own implementation for Coherence as was done here: http://middlewaremagic.com/weblogic/?p=8038.
          The complete code for that example can be found here: https://www.dropbox.com/sh/f5orcs55g7j57oj/XPhplq3aBh/Coherence/VoorbeeldSecondLevelCacheHibernate4.zip
          • 2. Re: Coherence as Hibernate L2 Cache
            Thanks René,

            That's a great suggestion about following other implementations (ehcache / infinispan), I'll investigate that more today.

            Also thanks for putting up all your content on http://middlewaremagic.com, I always learn a lot and you've helped me out on a few occasions.