ClassCastException received on application when accessing an EJB
 Technote (troubleshooting)
 
Problem(Abstract)
ClassCastException is received after a lookup is done on an EJB™ that resides in a different EAR file than the client.
 
Cause
When using local EJB references and the client/EJB are in different EAR files the cast after the lookup fails because two different classloaders are being used. This statement assumes the client has the default classloader settings within IBM® WebSphere® Application Server V5.0, V5.1 and V6.0.


When the container starts app1 and loads the EJB with its app classloader (EARCL1), the local ejb instance is bound to the JNDI namespace. When that EJB is resolved in another application, app2, a exception will occur when app2 casts the instance to its interface, because the interface was loaded by EARCL2, but the instance's interface class was loaded by EARCL1.
 
Resolving the problem
A local EJB reference cannot be utilized within two applications (EAR files) without special consideration.

These are the options to resolve this issue:

(1) Package the EJB client and the EJB in the same EAR file
(2) Use a single classloader for the whole JVM™
(3) Use a shared library

For more information on classloader settings see this techdoc.

 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > Classloader
Operating system(s): Windows
Software version: 6.0
Software edition:
Reference #: 1215909
IBM Group: Software Group
Modified date: Oct 21, 2008