2 Replies Latest reply: Jan 9, 2013 9:15 AM by 983682 RSS

    Coherence as Hibernate L2 Cache

    983682
      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)..
      http://coherence.oracle.com/pages/viewpage.action?pageId=16730
      and
      http://wiki.tangosol.com/display/COH33UG/Using+Coherence+and+Hibernate



      .here's the best that I've found online, cause I'm using hibernate4
      http://middlewaremagic.com/weblogic/?p=8038

      My major question is that the comments on
      org.hibernate.testing.cache.CachingRegionFactory

      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

      f


      <bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="hibernateProperties">
      <props>
      <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>
      </props>
      </property>
        • 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
                 @Override
               public void start(Settings settings, Properties properties) throws CacheException {
                    this.settings=settings;
               }
          
               @Override
               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
            983682
            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.

            thanks

            f