Once you've redeployed, you have a new class loader, so while the classes may
look the same (com.example.MyObject) they are actually distinct as far as the
JVM is concerned.
I don't have an easy fix ... clearing the cache explicitly when your app starts might
work in some cases.
thank you, for your answer, it makes perfect sense. If i change the class type to an array of primitives instead of my custom class, would that work? I'm not familiar on the intricacies of the classloader.
Also i forgot to say that clearing the cache is not an option as the app will be running on multiple servers sharing the same cache.
This brings up another question. How in the heck am i suppose to share data through the cache if i cant even get at the object data between multiple app instances?
I think what you should be doing is clear the local cache using JBossCache options API when undeploying your application. That will clear the cache and then start a new instance on redeployment which will have the right classes with the right defining class loader and you won't affect the other cache instances running on other instances of the application assuming that you're sharing the cache via replication, cache loader,...
- Yes, if you store primitive types rather than application types this problem won't occur
- This problem won't occur with remote marshalling of the class data, since object is sent in serialized form to remote nodes. This does point out another problem you are going to run into, however, which is harder to deal with than the one you've hit already ... to get sending your application classes to remote nodes to work, you need to set the class loader that the cache uses to demarshal objects read from the wire; this isn't too hard to do - use cache.registerClassLoader() - but you can't *change* the class loader for a running cache. So you basically need to either use primitive types or restart the cache for that node (not just clear it) when you redeploy your application.
- Are you really planning to change the code on one node of the cluster while leaving an older version running on another node? Brave.
Thanks for the info everyone. I seem to have fixed the problem by replacing my app data classes with arrays of primitives, or arrays of Objects which contain java library objects like Strings.