[jboss-user] [EJB 3.0] - Re: ClassCastExeption while invoking a Bean
atul.iims2005
do-not-reply at jboss.com
Mon Apr 7 04:20:17 EDT 2008
Dear Sir,
I am new to ejb, my problem is when i run my client program i get this error.
Anyone suggest me what i am doing wrong...........
This is my Exception which is generated during the client program execute.......
Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at Client.main(Client.java:27)
Caused by: java.lang.ClassCastException: $Proxy0 cannot be cast to org.omg.CORBA.Object
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
... 2 more
Could anyone tell me what Iâm doing wrong? Thanks a lot. Looking forward to hearing from you.
These are my code..........
********remote interface*******
package My;
import java.rmi.*;
import javax.ejb.*;
public interface DemoInter extends EJBObject
{
public int add() throws RemoteException;
}
************home interface***********
package My;
import javax.ejb.*;
import java.rmi.*;
public interface DemoHome extends EJBHome
{
public DemoInter create(int a, int b) throws CreateException,RemoteException;
}
*************bean class*************
package My;
import javax.ejb.*;
import java.rmi.*;
public class DemoBean implements SessionBean
{
int a,b;
private SessionContext context;
public void setSessionContext(SessionContext ctx){this.context=ctx}
public void ejbCreate( int a,int b)
{
this.a=a;
this.b=b;
System.out.println("ejb Created");
}
public void ejbActivate(){System.out.println("ejbActivate()");}
public void ejbPassivate(){System.out.println("ejbPassivate()");}
public void ejbRemove(){System.out.println("distroyed");}
public int add() throws RemoteException
{
return(a+b);
}
}
***********my client**************
import java.util.*;
import javax.rmi.PortableRemoteObject;
import javax.naming.*;
import javax.rmi.*;
import My.*;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Properties properties=new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
properties.put("java.naming.provider.url","ejbd://localhost:4201");
Context ctx=new InitialContext(properties);
System.out.println("ic = " + ctx);
//MyTimeLocal myTimeLocal = (MyTimeLocal)context.lookup("java:comp/env/ejb/MyTimeBean");
// My.DemoInter remoteObj =(My.DemoInter)ctx.lookup("ejb/mgmt/MEJBRemoteHome");
Object object=ctx.lookup("ejb/mgmt/MEJBRemoteHome");
// System.out.println("hello" +object);
My.DemoHome ejbHome =(My.DemoHome)PortableRemoteObject.narrow(object,My.DemoHome.class);
System.out.println("hello" +ejbHome);
My.DemoInter obj1=ejbHome.create(4,5);
System.out.println(obj1.add());
} catch (Exception e) {
System.out.println(e);
// TODO: handle exception
}
}
}
this is log file..........
13:02:24,839 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:30,987 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:34,611 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:35,732 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:40,045 INFO [config] Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
13:02:40,045 INFO [config] Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
13:02:40,045 INFO [config] Configuring Service(id=Default BMP Container, type=Container, provider-id=Default BMP Container)
13:02:40,046 INFO [config] Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
13:02:40,046 INFO [config] Configuring app: default/ejbsample1.jar/1207553559310/jar
13:02:40,078 INFO [OpenEJB] Auto-deploying ejb DemoEJB: EjbDeployment(deployment-id=ejbsample1.jar/DemoEJB)
13:02:40,079 INFO [config] Loaded Module: default/ejbsample1.jar/1207553559310/jar
13:02:40,976 INFO [startup] Assembling app: /home/atul/santemp/geronimo-tomcat6-javaee5-2.1/var/temp/geronimo-deployer17419.tmpdir/ejbsample1.jar
13:02:40,985 INFO [startup] Jndi(name=DemoEJBRemoteHome) --> Ejb(deployment-id=ejbsample1.jar/DemoEJB)
13:02:40,985 INFO [startup] Created Ejb(deployment-id=ejbsample1.jar/DemoEJB, ejb-name=DemoEJB, container=Default Stateless Container)
13:02:40,985 INFO [startup] Deployed Application(path=/home/atul/santemp/geronimo-tomcat6-javaee5-2.1/var/temp/geronimo-deployer17419.tmpdir/ejbsample1.jar)
13:02:41,083 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141982#4141982
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141982
More information about the jboss-user
mailing list