ClassCastException while accessing EJB
Following is my code of client to access session bean using local interface:
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class HelloClient {
public static void main(String args[]) throws Exception {
Hashtable h=new Hashtable();
h.put(Context.PROVIDER_URL,"jnp://192.168.45.277:1045");
h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
Context ctx=new InitialContext(h);
Object obj=ctx.lookup("Hello");
HelloLocalHome home=(HelloLocalHome)obj;
HelloLocal hello=home.create();
System.out.println(hello.hello());
hello.remove();
}
}
-------------------------------------------END of client code----------------------------
Below is content of deployment descriptor
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN" " http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</home>
<remote>examples.Hello</remote>
<local-home>examples.HelloLocalHome</local-home>
<local>examples.HelloLocal</local>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
---------------------------------------END of DD-----------------------------------------
Problem is that when run my client code I get ClassCastException at line which is bolded. Application is deployed successfully on JBoss as I can access using remote interface but local interface is giving this trouble. Please help me.