title: How to clear the Infinispan cache
body: <p>In my project, we use infinispan as 2nd Level cache in combination with Hibernate 4. This is the entry from the persistence.xml</p>
  
  <p></p>
  
  <pre><code>&lt;jta-data-source&gt;java:jboss/datasources/RuleEngine&lt;/jta-data-source&gt;        
    &lt;shared-cache-mode&gt;ALL&lt;/shared-cache-mode&gt;
    &lt;properties&gt;
      &lt;property name="hibernate.show_sql" value="false" /&gt;
      &lt;property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect"/&gt;
      &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
      &lt;property name="hibernate.cache.use_query_cache" value="true"/&gt;
      &lt;property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/RuleEngineCache"/&gt;
      &lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"/&gt;
    &lt;/properties&gt;
  </code></pre>
  
  <p>   </p>
  
  <p>What I wanted to do is to clear the cache when hitting a button on the GUI. The java code is:</p>
  
  <pre><code>CacheManager cm = new DefaultCacheManager();
  Cache&lt;Object, Object&gt; c = cm.getCache();
  c.clear();
  </code></pre>
  
  <p>I added this code to my web project.</p>
  
  <p>But I get an exception on the first line saying <code>Failed to define class org.infinispan.io.ExposedByteArrayOutputStream in Module "deployment.RuleEngineWS-ear.ear.RuleEditor-1.2.0-SNAPSHOT.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/infinispan/io/ExposedByteArrayOutputStream (Module "deployment.RuleEngineWS-ear.ear.RuleEditor-1.2.0-SNAPSHOT.war:main" from Service Module Loader)</code>
  <br/>
  Caused by <code>java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput</code> <br/>
  Caused by <code>java.lang.ClassNotFoundException: org.jboss.marshalling.ByteOutput</code></p>
  
  <p>The cache itself is working properly, I just have problems explicitly accessing it. I thought that I will get the one and only CacheManager if I call <code>new DefaulCacheManager()</code> but then also using this Interface is deprecated.</p>
  
  <p>So if I am totally on the wrong path, how can I delete my cache then?</p>
  
  <p>Infinispan 5.2.6</p>
  
  <p>EDIT:
  Also I tried injecting the CM by using several tries and especially the <code>@Resource(lookup="java:jboss/infinispan/RuleEngineCache")</code> annotation. But it is not injected, whether I use EmbeddedCacheManager as in the quickstart example or the deprecated CacheManager.</p>