• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

java.lang.ClassCastException During lookup the Local Interface

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I got the following error during the lookup time of Local interface, please help me to solve the problem. ( Websphere 6.0.1, Jsp, EJB2 )

--------
error
------
R java.lang.ClassCastException: test.EJSLocalStatelesscounterHome_8ada3073
at com.ibm._jsp._EJBTest._jspService(_EJBTest.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:117)
at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java:171)

-------------------------------------------------------------------------
ejb-jar.xml
-----------

<enterprise-beans>
<session id="Session_MyTime">
<description>An EJB named counter</description>
<display-name>Ejb Lccal Counter</display-name>
<ejb-name>Counter</ejb-name>
<local-home>test.CounterLocalHome</local-home>
<local>test.CounterLocal</local>
<ejb-class>test.CounterBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref>
<description>This is a Counter session</description>
<ejb-ref-name>ejb/Counter</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>test.CounterLocalHome</local-home>
<local>test.CounterLocal</local>
<ejb-link>Counter</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
</ejb-jar>

-------------------------------------------------------------------
Client code ( JSP client)
------------------------
try {
InitialContext context = new InitialContext();
out.println("Context created.....");
CounterLocalHome home =(CounterLocalHome)context.lookup("java:comp/env/ejb/Counter");
CounterLocal remote=home.create();
out.println(" hit count....."+remote.hit()); out.println(" === finished ===== ");
}
catch (Exception e) {
out.println(e);
e.printStackTrace();
}


%>

------------------------------------------------------------------------
web.xml
--------
<web-app id="WebApp_ID" version="2.4"<br /> xmlns="http://java.sun.com/xml/ns/j2ee"<br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br /> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee <a href="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; rel="nofollow">" target="_blank">http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">;
<display-name>
counter</display-name>
<ejb-local-ref>
<ejb-ref-name>ejb/Counter</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>test.CounterLocalHome</local-home>
<local>test.CounterLocal</local>
<ejb-link>Counter</ejb-link>
</ejb-local-ref>
</web-app>


=================================================================
I try to Print the lookup Class before going to cast. it print the classs name is

out.print("Output="+context.lookup("java:comp/env/ejb/Counter").toString());

Output === test.EJSLocalStatelesscounterHome_8ada3073@181b8107(BeanId(__homeOfHomes#__homeOfHomes#__homeOfHomes, counter_jar#counter.jar#counter))


please help me to solve the problem....... Advance Thanks.............
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic