1 Reply Latest reply on Jul 8, 2013 10:19 AM by Sandy Sandy

    Issue with Infinispan JPA

    Sandy Sandy Newbie

      Hi Guys,

       

      I am working on a legacy application which has lot of Cache Data(2 GB which is read-only) and there was a stage when application wouldnt start up because of the increasing data day-by-day. I have implemented Infinispan in Distributed cache mode with a cluster of 4 servers and a replication factor of 2. The design is that the existing code populates the data in the same way but using the Hotrod API to the remote Infinispan cache. Now, the application starts up like magic and the server memory has also been reduced to 1 GB. Infinispan worked brilliantly.

       

      Now we are planning to remove the start up caching code from the application(there by improving the startup time of the application and allowing independent restarts of inifinispan) and use the same code in Infinispan Custom Cache loader. Reason being - the cache object structure is complex and Pure JPA store doesnt look to suffice. The structure is HashMap<String, <HashMap<String, A Complex Type>>>. With this, even if there are changes in the complex type/db structure, i can update the complex type in client code and corresponding code in infinispan.

       

      I have seen the code for JPA Cache Loader and I am trying to update few methods in it, to mimic the same structure used by the legacy application. I have implemented the methods and deployed the same to Infinispan. On Start-up, I am getting the below exception.

       

      The Cache instance looks to be created and the properties defined in the Infinispan Config XML looks to be set(persistence unit name and the entity) but an exception is thrown while JPA - Hibernate code is invoked to fetch EntityManagerFactory particularly at the below statement.

       

      emf = emfRegistry.getEntityManagerFactory(config.getPersistenceUnitName());

       

       

      <strong>This initially looked like Hibernate exception but when I wrote a main method to test the same methods in a stand-alone java project, it works and the data is fetched properly.<strong>

       

      Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

              at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:197)

              at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:1

      33)

              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(Hib

      ernatePersistence.java:55)

              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.

      java:63)

              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.

      java:47)

              at org.infinispan.loaders.jpa.test.EntityManagerFactoryRegistry.getEntit

      yManagerFactory(EntityManagerFactoryRegistry.java:22)

            <strong>  at org.infinispan.loaders.jpa.test.JpaCacheStore.start(JpaCacheStore.jav

      a:90)

              at org.infinispan.loaders.CacheLoaderManagerImpl.start(CacheLoaderManage

      rImpl.java:152)</strong>

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

              at java.lang.reflect.Method.invoke(Unknown Source)

              at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.ja

      va:203)

              ... 27 more

      Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

              at java.net.URLClassLoader$1.run(Unknown Source)

              at java.net.URLClassLoader$1.run(Unknown Source)

              at java.security.AccessController.doPrivileged(Native Method)

              at java.net.URLClassLoader.findClass(Unknown Source)

              at java.lang.ClassLoader.loadClass(Unknown Source)

              at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

              at java.lang.ClassLoader.loadClass(Unknown Source)

       

      This initially looked like Hibernate exception but when I wrote a main method to test the same methods in a stand-alone java project, it works and the data is fetched properly. The issue looks particularly due to the class org.slf4j.LoggerFactory not loaded properly. But this jar for this(slf4j-api-1.6.1.jar) is included in the classpath and the class is present. But with Inifinispan it is somehow not able to load the class.

       

      I have attached the Java Project that is used to test the hibernate code(JPACacheStore.java - which also the cache loader class), start-up script and Infinispan XML. I have deployed the same jar to Infinispan and updated the start-up script to include the POJOs, the Cache Loader and the dependencies.

       

      Could somebody please give inputs on these.