Reputation: 143
I have two portal web project
project1
project2
I have a shared library(sharedLibrary.jar) set which is used in both the above project. My shared library is used to lookup dyna cache and set/get data from it.
I am setting a my own bean bean(say it is com.test.UserBean) to dyna cache from project 1.
Now from project 2 am trying to retrieve the bean(com.test.UserBean) from cache. When doing so i am getting classCastException.
but when I assign it like below it was showing me the that the object is com.test.UserBean
Object obj=distributedMap.get(); My bean implements Serializable interface and has a serialVersionUID field.
I am not sure what happening here. Is it a class loader issue/something else.
Can any one shed some more light on this ?
Upvotes: 0
Views: 827
Reputation: 3424
This is less likely a serialization issue and more likely a classloader issue.
If the class was truly loaded by both portlet web applications by a single, common class loader then instances can be shared via DynaCache.
If however two different classloaders are used to load the same .class from the same .jar (on disk) and the two applications share a single instance (e.g. via DynaCache distributed map) you will encounter a ClassCastException
- even though, as you've seen, myInstance.getClass().getName()
yields the same string.
To confirm this you can enable a service and use the WebSphere classloader viewer. This will let you, per module, troubleshoot your "two classloaders, one class" issue. There is a companion doc on the InfoCenter doc which walks you through the troubleshooting process. The classloader viewer will show you which .jar and which classloader was used to load the com.test.UserBean
in each module. For example, you may have accidentally packaged the jar in WEB-INF/lib of one and not the other and have parent-last classloading enabled.
Upvotes: 1