This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Going crazy casting local home interface

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() {
super();}

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.
Walter
 
author & internet detective
Posts: 39959
804
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Walter,
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.
 
Walter Chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
Walter
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic