4 Replies Latest reply on Apr 6, 2012 3:03 AM by varkon

    Error when trying to manually evict 2nd-level cache in AS7.1.1.Final using Infinispan

    varkon Newbie

      Hello,

       

      I'm using the embedded Infinispan implementation in JBossAS7.1.1.Final, as my JPA 2nd-level cache. The cache seems to be working just fine during normal transactions.

      Below is the cache configuration used in my persistence.xml.

       

      {code:xml}

      <property name="hibernate.cache.use_second_level_cache" value="true"/>

      <property name="hibernate.cache.use_minimal_puts" value="true"/>

      <property name="hibernate.cache.use_query_cache" value="true" />

      <property name="hibernate.cache.default_cache_concurrency_strategy" value="TRANSACTIONAL"/>

      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>

      <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate"/>

      {code}

       

      At some point, I decides I needed a way to manually clear the cache.

      I have created two methods for cache eviction, one using the JPA api, the other one Hibernate's.

       

      {code}

      public void evictCacheJpa(){

           javax.persistence.Cache cache = em.getEntityManagerFactory().getCache();

           cache.evictAll();

      }

       

      public void evictCacheHibernate(){

           HibernateEntityManagerFactory hEmf = (HibernateEntityManagerFactory)em.getEntityManagerFactory();

           Cache cache = hEmf.getSessionFactory().getCache();

           cache.evictEntityRegions();

           cache.evictCollectionRegions();

           cache.evictDefaultQueryRegion();

           cache.evictQueryRegions();

      }

      {code}

       

      In both of the above cases, I get the following error:

       

      {quote}

      java.lang.NullPointerException: javax.ejb.EJBException: java.lang.NullPointerException

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

           ....

      Caused by: java.lang.NullPointerException

          at org.hibernate.cache.infinispan.util.CacheAdapterImpl.broadcastEvictAll(CacheAdapterImpl.java:223) [hibernate-infinispan-4.0.1.Final.jar:4.0.1.Final]

          at org.hibernate.cache.infinispan.access.TransactionalAccessDelegate.evictAll(TransactionalAccessDelegate.java:166) [hibernate-infinispan-4.0.1.Final.jar:4.0.1.Final]

          at org.hibernate.cache.infinispan.entity.TransactionalAccess.evictAll(TransactionalAccess.java:31) [hibernate-infinispan-4.0.1.Final.jar:4.0.1.Final]

          at org.hibernate.internal.SessionFactoryImpl$CacheImpl.evictEntityRegion(SessionFactoryImpl.java:1339) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

          at org.hibernate.internal.SessionFactoryImpl$CacheImpl.evictEntityRegions(SessionFactoryImpl.java:1345) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

           ...

      {quote}

       

      I can provide the complete stacktrace if required. Both methods fail with the same message, and the same cause, specifically:

       

      {quote}java.lang.NullPointerException at org.hibernate.cache.infinispan.util.CacheAdapterImpl.broadcastEvictAll(CacheAdapterImpl.java:223){quote}

       

      Is there an error in my configuration? Is there another way to clear the cache? Any help would be greatly appreciated.

       

      Environment:

      OS: Windows 7 (64-bit)

      JAVA: 7 update 3 (32-bit)

      AS: 7.1.1.Final (on 32-bit JVM)

       

      Best regards,

       

      Dimitris