5 Replies Latest reply on Nov 8, 2017 10:14 AM by clagio

    cache.clear inside a batch

    clagio Newbie


      It's possible to use a cache.clear inside a batch transaction?

      I have a code like this:





      Which gives the following error:


      ERROR: ISPN000136: Error executing command SizeCommand, writing keys []

      java.lang.IllegalStateException: Transaction EmbeddedTransaction{xid=Xid{formatId=1, globalTransactionId=85C51E23E9A44DF629C6535A1060461F0000000000000003,branchQualifier=85C51E23E9A44DF629C6535A1060461F0000000000000003}, status=COMMITTED} is not in a valid state to be invoking cache operations on.

              at org.infinispan.interceptors.impl.TxInterceptor.enlist(TxInterceptor.java:486)


      If I move the cache.clear outside the batch, I don't have errors... Checking the code behind cache.clear in the Cache.java I see the following comment:


        * Removes all mappings from the cache.
        * <p/>
        * <b>Note:</b> This should never be invoked in production unless you can guarantee no other invocations are ran
        * concurrently.
        * <p/>

        * If the cache is transactional, it will not interact with the transaction.


      Could be that there is a conflict between the startbatch transaction and the transaction (?) started by the cache.clear?