3 Replies Latest reply on Mar 2, 2016 2:13 AM by galder.zamarreno

    Infinispan 8 support for Hibernate 3.6 hibernate.cache.provider_class

    haiaw

      I have below Hibernate 3.6 configuration and want to switch to Infinispan 8. Is it possible?

      Our solution is based on old JBoss cache 1.4 TreeCache. Infinispan was forked some time ago and today it also has TreeCache in its structure and documentation with suggestion to migrate from old TreeCache to new one.

       

      Tree API Module

      Infinispan’s tree API module offers clients the possibility of storing data using a tree-structure like API. This API is similar to the one provided by JBoss Cache, hence the tree module is perfect for those users wanting to migrate their applications from JBoss Cache to Infinispan, who want to limit changes their codebase as part of the migration. Besides, it’s important to understand that Infinispan provides this tree API much more efficiently than JBoss Cache did, so if you’re a user of the tree API in JBoss Cache, you should consider migrating to Infinispan.

       

       

      <prop key="hibernate.dialect">${db.dialect}</prop>

                          <prop key="hibernate.show_sql">${show.sql}</prop>

                          <prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>

                          <prop key="hibernate.cache.provider_class">Custom org.jboss.hibernate.jbc.cacheprovider.TreeCacheProvider</prop>

                          <prop key="hibernate.cache.use_second_level_cache">FALSE</prop>

                          <prop key="hibernate.cache.use_query_cache">TRUE</prop>

       

       

      Here is old cache provider:

       

       

          public class CustomTreeCacheProvider extends TreeCacheProvider implements org.hibernate.cache.CacheProvider {

         

              private TreeCache cache;

            

              private TransactionManager transactionManager;

       

              private CacheProperties cacheProperties;

           

              public Cache buildCache(String regionName, Properties properties) throws CacheException {

               

                  return new JBCCache(cache, regionName, cacheProperties, transactionManager);

                

              }

        

              public long nextTimestamp() {

                  return System.currentTimeMillis() / 100;

              }

        

              public void start(Properties properties) throws CacheException {

               

                  try {

                      cache = new org.jboss.cache.TreeCache();

                      cacheProperties = new CacheProperties(properties);

                      PropertyConfigurator config = new PropertyConfigurator();

                   

                      config.configure(cache, ""someXMLfile.xml"");

                   

                      TransactionManagerLookup tml = TransactionManagerLookupFactory.getTransactionManagerLookup(properties);

                   

                      if (tml!=null) {

                          cache.setTransactionManagerLookup( new TransactionManagerLookupAdaptor(tml, properties) );

                          transactionManager = tml.getTransactionManager(properties);

                   

                      }

                      cache.start();

                  }

                  catch (Exception e) {

                      throw new CacheException(e);

                  }

              }

        

              public void stop() {

                  if (cache!=null) {

                      cache.stopService();

                      cache.destroyService();

                      cache=null;

                  }

              }

       

              static final class TransactionManagerLookupAdaptor implements org.jboss.cache.TransactionManagerLookup {

                  private final TransactionManagerLookup tml;

                  private final Properties props;

                  TransactionManagerLookupAdaptor(TransactionManagerLookup tml, Properties props) {

                      this.tml=tml;

                      this.props=props;

                  }

                  public TransactionManager getTransactionManager() throws Exception {

                      return tml.getTransactionManager(props);

                  }

              }

             

          }

        • 1. Re: Infinispan 8 support for Hibernate 3.6 hibernate.cache.provider_class
          nadirx

          Infinispan 8 must be used with Hibernate 5. The latest Infinispan you can use with Hibernate 3.6 is probably 5.2.x, but I would guarantee it much, since they are both very old releases.

          • 2. Re: Infinispan 8 support for Hibernate 3.6 hibernate.cache.provider_class
            haiaw

            Thannks for the answer,

             

            Little more questions:

             

            1)  Why it would not work in Hibernate 3.6 ?


            2) AS for Hibernate l2 cache, maybe I could use net.sf.ehcache.hibernate.EhCacheProvider instead of Infinispan ?

             

            3) Where could I find this information (relation between Infinispan/Spring/Hibernate) ? I've search this and didn't find..

            I would like to know which versions are good for Hibernate 3.6 / 4 / 5 and which for Spring 3 / 4


            4) Besides, isnt it possible to provide CustomCacheProvider basing on Infinispan 8 Treecache and extending some Hibernate org.hibernate.cache.CacheProvider ?

            • 3. Re: Infinispan 8 support for Hibernate 3.6 hibernate.cache.provider_class
              galder.zamarreno

              1) There is an integration layer which might not be compatible with it, e.g. APIs change..etc.

              2) I've not used that caching provider before, so can't say about its capabilities.

              3) I'm not sure we have that mapping available, but this is open source and you're free to browse the code and see which versions each Hibernate version depend on, e.g. here. We try to keep backwards compatibility as much as possible, so you might find more recent versions of Infinispan might work with a specific Hibernate version.

              4) I think you'd be much better off upgrading to a more recent Hibernate version than trying to do that.