wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Not able to excute EJB ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Not able to excute EJB ClassCastException" Watch "Not able to excute EJB ClassCastException" New topic
Author

Not able to excute EJB ClassCastException

Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
I have created an EJB module and a web module.
When I try to run EJB from a servlet I get ClassCastException. I do not know why?

I am using intelliJ Idea (IDE) and JBoss 4.0.2 application server.

I get ClassCastException When I try to narrow after lookup.

I have seen many sites but i could not resolve this problem.

Can some one help on this?

Please find below the code details.

jboss.xml
-----------------------------------------------
<jboss>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<jndi-name>ejb/Hello</jndi-name>
</session>
<session>
<ejb-name>TesterBean</ejb-name>
<jndi-name>test/Tester</jndi-name>
</session>

</enterprise-beans>
</jboss>


ejb-jar.xml
-----------------------------------------------
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>com.wiley.examples.HelloHome</home>
<remote>com.wiley.examples.Hello</remote>
<ejb-class>com.wiley.examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

<session>
<display-name>TesterBean</display-name>
<ejb-name>TesterBean</ejb-name>
<home>com.wiley.examples.TesterHome</home>
<remote>com.wiley.examples.Tester</remote>
<ejb-class>com.wiley.examples.TesterEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

jboss-web.xml
-----------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
<ejb-ref>
<ejb-ref-name>ejb/HelloEjb</ejb-ref-name>
<jndi-name>ejb/Hello</jndi-name>
</ejb-ref>
</jboss-web>


web.xml
-----------------------------------------------------
<ejb-ref>
<ejb-ref-name>ejb/HelloEjb</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.wiley.examples.HelloHome</home>
<remote>com.wiley.examples.Hello</remote>
<ejb-link>Hello</ejb-link>
</ejb-ref>


code from servlet
---------------------------------------------------
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming rg.jnp.interfaces");
env.put("org.omg.CORBA.ORBInitialHost","localhost");
env.put("org.omg.CORBA.ORBInitialPort","3700");

Context context = new InitialContext();
Object object = context.lookup("java:comp/env/ejb/HelloEjb");
System.out.println(object);
HelloHome helloHome = null;
if (object != null) {
// PortableRemoteObject.narrow(object, HelloHome.class);
helloHome = (HelloHome)PortableRemoteObject.narrow(object, HelloHome.class);

Hello hello = helloHome.create();
System.out.println(hello.hello());
}

I am able to compile entire code but When i excute EJB's I get ClassCastException on PortableRemoteObject.narrow(object, HelloHome.class);

Please help.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, ITIL V3 Foundation Certification
Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
I am able to resolve this using galssfish server, but there was some problem with JBoss.

-Lave
 
 
subject: Not able to excute EJB ClassCastException
 
Similar Threads
NameNotFoundException in EJB? could anyone tell me?
NameNotfoundexception
Why can't I invoke a ejb in Tomcat?
naming exception
NameNotFoundException in EJB? could anyone tell me?