Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Websphere and the fly likes Going crazy casting local home interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Going crazy casting local home interface" Watch "Going crazy casting local home interface" New topic

Going crazy casting local home interface

Walter Chen

Joined: Jan 10, 2003
Posts: 25
This is weird! Say I have a session bean with a local home and local interfaces. From the client, I could get the local home interface by JNDI look-up, this is my code:

Object obj = initial.lookup("java:comp/env/ejb/MySessionLocal");
System.out.println("Looked up local home, class is: " + obj.getClass());

The System.out prints out something like the following:

Looked up local home, class is: ejbs.EJSLocalMySessionHome_5c39c28d

So, ejbs.EJSLocalMySessionHome_5c39c28d is the stub. I looked at the code inside this file, it has the following:

public class EJSLocalMySessionHome_5c39c28d extends EJSLocalWrapper implements ejbs.MySessionLocalHome {

public EJSLocalMySessionHome_5c39c28d() {

So far so good. It is clear that this stub implements the local home interface ejbs.MySessionLocalHome

However, in my client code, when I do the following:

ejbs.MySessionLocalHome mySessionHomeIf = (ejbs.MySessionLocalHome) obj;

I get a ClassCastException. How can this be? It DOES implement the home interface, why can't I cast it???

Thanks in advance.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 30764

Often that has to do with bad deployed code or different JVMs. Since you are using a client, it is probably different JVMs.

What kind of client is this? Usually a client cannot make local EJB calls.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Walter Chen

Joined: Jan 10, 2003
Posts: 25
The client and server are running on the same server inside the same JVM, I am using Websphere 6.0, I will check the VM tomorrow, but I believe it is IBM's standard VM.

wood burning stoves
subject: Going crazy casting local home interface