Troubleshooting
Problem
You receive a ClassCastException when casting a remote Enterprise Java™Beans home or remote interface stub instance to its actual remote home interface or remote interface type. When resolving a remote EJB home reference or a local EJB home reference, an application programmer may "cleverly" attempt to narrow the result of a JNDI lookup using the EJBHome class rather than the exact home class (type) in order to generalize the task. Here is an example involving a remote Enterprise JavaBeans, MyBean and it's corresponding home, MyHome:
[]
InitialContext context = new InitialContext();
Object remoteObj = context.lookup("java:comp/env/ejb/MyHomeName");
EJBHome ejbHome = PortableRemoteObject.narrow(remoteObj, EJBHome.class):
MyBean myBean = (MyBean)ejbHome.create();
...
[
]
Symptom
In this example, a ClassCastException indicating class MyBean_Stubxxx occurs when the application casts the result of myHome.create() to class MyBean. The explanation is provided below.
A ClassCastException occurs if myHome (an instance of EJBHome, above) is cast to its actual type, MyHome. The following example statements also result in a ClassCastException indicating the MyHome_Stubxxx class:
MyHome myHome = (MyHome)ejbHome;
Which is synonymous with:
MyHome myHome = (MyHome)PortableRemoteObject.narrow(object, EJBHome.class):
Because the code snippets above violate the Enterprise JavaBeans 2.0 specification with regard to narrowing remote EJB references, their expected behavior is indeterminate.
To view more of this document
Was this topic helpful?
Document Information
More support for:
WebSphere Application Server
Software version:
9.0, 8.5.5, 8.0, 7.0
Operating system(s):
AIX, HP-UX, Linux, Solaris, Windows
Document number:
81059
Modified date:
03 March 2025
UID
swg21192568