title: ClassCastException while reading from Infinispan Cache after redeployment on Wildfly 8.2
body: <p>I have a simple Infinispan local-cache (also tried distributed cache) on Wildfly 8.2. Everything is working fine until I do redeployment of my .WAR. After redeployment of my .WAR I get the following error:</p>
  
  <pre><code>Caused by: java.lang.ClassCastException: my.package.MyClass cannot be cast to my.package.MyClass
  </code></pre>
  
  <p>Full stacktrace: <a href="https://gist.github.com/bagges/07af1842a874f7c99ef3" rel="nofollow">https://gist.github.com/bagges/07af1842a874f7c99ef3</a></p>
  
  <p>I lookup the Cache in a CDI Bean like this:</p>
  
  <pre><code>@Path("/mypath")
  @Stateless
  public class MyServiceClass {
  
      @Resource(lookup = "java:jboss/infinispan/myContainer")
      private CacheContainer container;
  
      private Cache&lt;Integer, MyCacheObject&gt; myCache;
  
      @PostConstruct
      public void start() {
          myCache = container.getCache("myCache");
      }
  
      @GET
      public String get() {
          if(!myCache.containsKey(1)) {
              myCache.put(1, new MyCacheObject(1, "Hello Cache"));
          }
          return myCache.get(1).getName();
      }
  }
  </code></pre>
  
  <p>Wildfly-Config:</p>
  
  <pre><code>&lt;cache-container name="myContainer" jndi-name="java:jboss/infinispan/myContainer" start="EAGER"&gt;
      &lt;local-cache name="myCache"/&gt;
  &lt;/cache-container&gt;
  </code></pre>
  
  <p>I know that the error occured because off different class loaders. Infinispan tries to cast the entity stored with the previous classloader which cannot work. But how to avoid this?</p>