Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ClassCastException while accessing EJB

843830Jul 28 2006
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2006
Added on Jul 28 2006
0 comments
145 views