• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to excute EJB ClassCastException

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Lave Kulshreshtha
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to resolve this using galssfish server, but there was some problem with JBoss.

-Lave
 
It means our mission is in jeapordy! Quick, read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic