Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A strange thing is happening here , i have no clue,pl help

 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have deployed an application with 2 jars and one war file.
war file has two JSP pages and two javaBeans.

now when i run my application either one of the ejbBean is working means if 1st ejb is working then 2nd one is giving error and vice versa.
they are giving following error:
java.lang.ClassCastException
at com.sun.corba.ee.internal.javax.rmi.PortableRemoteObject.narrow(Portab
leRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
i am stuck to this problem from last week.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need more information. Normally a ClassCastException message indicates the type of class it's trying to cast to. Also, the source code context where you are getting the exception would be useful.
 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when loginBean is working then i get error in category bean , if category bean is working then i get error in login bean
i am sure the erroris on this line
java.lang.Object objref = ic.lookup("java:comp/env/ejb/Category");
objref is not getting initiated
i am getting error on this code in CategoryBean.java
Context ic = new InitialContext();
java.lang.Object objref = ic.lookup("java:comp/env/ejb/Category");
catHome = (CategoryHome) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
LoginBean.java
Context ic = new InitialContext();
java.lang.Object objref = ic.lookup("java:comp/env/ejb/Login");
loginHome = (LoginHome) PortableRemoteObject.narrow(objref,ejbBeans.LoginHome.class);
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your bean stateless?
 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes both bean is stateless
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Rohit,
Are the EJB's talking to each other?.
If they are talking to each other then have you given the
entiy references of one bean to other.
If one EJB is talking to another EJB then you have to mention
in your DD,
1) The EJB coded name
2)The remote Interface
3)And the Home interface of the other EJB.
in the entity references.
Hope this helps,
Manjuanth
 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what i am doing is that i am showing categories on a page but before it verifies that user is login or not, if not then it is redirected to login screen and asks userlogin and password.
all this is done through JSP. Now login form is submitted and its login name and login password is checked through stateless session bean i.e LoginEJB.if he exists then it sets sessions.
now it is redirected back to category screen where the categories are shown from CategoryEJB bean.
now what i have done is i have made one jar file for login bean and one for category bean through j2ee deploytool.
i also made one war file which contains JSP files,i.e auc_login.jsp,auc_sell_product.jsp,LoginBean.class and Category.class.
LoginBean and CategoryBean are java beans which acts client to their respective ejb's.
i have deployed them through an one application when i run the application, it reflects to login screen,after submitting login form it verifies the user but gives above error in CategoryBean. again if closes this window and open another window then again it asks login screen but this time after submitting the login form it gives above errors in loginBean but categoryBean is working(that i come to know through console where it shows me al the happenings).
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ever met ClassCastException when I was using EJB in JSP.The post of Nauman Rafique's help me to solve my problem.Refer to:
http://www.javaranch.com/ubb/Forum11/HTML/000231.html
------------
ruijin yang
SCJP2
 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilya,
Thanks for giving me solutions, actualy j2ee deploytool generates the stub classes automaticaly.
i have seen that, any way i think i been wrong some where else but could not able trace the error.
I have done it with taking two other ejb beans.
in j2ee there is no need to do anything explicitly as deploytool will do it for you. thanks all for helping me.
Rohit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic