[jboss-user] [Beginners Corner] - Please help with EJB3 ClassCastException.

kingcu do-not-reply at jboss.com
Fri Jan 12 18:45:57 EST 2007


Hi Friends,

I am writing my first ejb 3 project that has a simple stateless session bean, which is accessed by my struts action class. Here is how the bean class looks like:    
        
        @Stateless
  |         @Local ({BeanLocal.class})
  |         @LocalBinding (jndiBinding="myapp/BeanLocal")
  |         @Remote ({BeanRemote.class})
  |         @RemoteBinding (jndiBinding="myapp/BeanRemote")
  |         public class Bean implements BeanLocal, BeanRemote {
  |             ...
  |         }
  | 


However, I got ClassCastException in my action class when trying to cast the bean to its local/remote interface type:

        BeanLocal bl = (BeanLocal) jndiContext.lookup("myapp/BeanLocal");

or for remote interface:

        Object ref = jndiContext.lookup("myapp/BeanRemote");
  |         BeanRemote br = (BeanRemote) PortableRemoteObject.narrow(ref, BeanRemote.class);
  | 


I am using JBoss Eclipse IDE 1.6 and running JBoss AS 4.0.5. The EJB 3 code is packaged into ejb-jar.jar and the web app is in its war file, then both the jar and the war are packed into an ear file.

Can someone please help me figure out what's wrong here?

Thanks,
Tong

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4001168#4001168

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4001168



More information about the jboss-user mailing list