This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes ClassCast exception working with Remote session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ClassCast exception working with Remote session bean" Watch "ClassCast exception working with Remote session bean" New topic
Author

ClassCast exception working with Remote session bean

kaarthik asokkumar
Greenhorn

Joined: Jan 21, 2005
Posts: 29
hi
I am working with EJB3 in jboss container using a eclipse id. I created a test session bean(stateless) and created a remote interface. I have my ejb in a separate ear and i am trying to access the ejb through from UserInterface ear (differrent ear but they share the same jvm). I get a class cast exception

Object ob = context.lookup("pfmbusinessenterprise/CalculatorBean/remote");
CalculatorRemote calc = (CalculatorRemote) PortableRemoteObject.narrow(ob, CalculatorRemote.class);

I explicitly created CalculatorRemote interface in the UserInterface ear.

I dont get this error when i explicitly add the ejb application as a dependency. I dont want to do this as i wanted to have the 2 ears separate.

JNDI look up is fine but its the casting that is causing a problem. I dont know what i am missing..

java.lang.ClassCastException
18:33:18,996 ERROR [STDERR] at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
18:33:18,996 ERROR [STDERR] at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
18:33:18,996 ERROR [STDERR] at business.test.clienttest.test(clienttest.java:13)


@ Stateless
public class CalculatorBean implements CalculatorRemote {

public String test (){
return "You are ok";
}
}

import javax.ejb.Remote;

@Remote
public interface CalculatorRemote {
public String test ();
}

Any help would be great.


SCJP 1.4, SCWCD 1.4,SCBCD 1.3.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

Try not using the PortableRemoteObject...


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
kaarthik asokkumar
Greenhorn

Joined: Jan 21, 2005
Posts: 29
i think i know what the issue is. I need to generate my stubs. Can any one please share some experience on generating the stubs using eclipse and jboss ??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ClassCast exception working with Remote session bean