-
I am having a grave problem when deploying beans. It gives ClassCastException. I am using weblogic server. The error occurs when I lookup the bean with the help of jndi.
I am using a jsp as the client. Sometimes in the first attempt it works fine but the second time onwards it gives the error like
( java.lang.ClassCastException:xxxBeanHomeImpl_WLStub )
Could any one tell me how to avoid this headache.
thanx in anticipation
tony
-
In order to avoid ClassCastException,u try by doing
like this.ie use PortableRemoteObject inorder to get an
instance of home object
<html>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.rmi.PortableRemoteObject" %>
<%
DepositHome depositHome=null;
Deposit deposit=null;
WithdrawHome withdrawHome=null;
Withdraw withdraw=null;
%>
<%
try {
Context ctx = new InitialContext();
System.out.println("context found");
java.lang.Object dref = ctx.lookup("transBeanDeposit");
java.lang.Object wref =ctx.lookup("transBeanWithdraw");
System.out.println("reference found");
depositHome =(DepositHome)PortableRemoteObject.narrow(dref,DepositHome.class);
withdrawHome =
(WithdrawHome)PortableRemoteObject.narrow(wref,WithdrawHome.class);
-
Thanks vinoth for the response,
I tried it but its still giving the error.
I have tried both the ways
1)
Object obj=ctx.lookup("transBeanDeposit");
System.out.println(obj.getClass().getName());
//this prints - Class DepositHomeImpl_WLStub
DepositHome home=(DepositHome)obj;//This statement gives the error
// The error is ClassCastException:DepositHomeImpl_WLStub
2)
Object obj=ctx.lookup("transBeanDeposit");
DepositHome home1=(DepositHome)PortableRemoteObject.narrow (obj, DepositHome.class);//Again Error
//java.lang.ClassCastException
//at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:90)
// I think the error is at PortableRemoteObject.narrow(ojb,DepostiHome.class);
I went through some documents at it said this error could also be due to the classloaders of the servers.
so I am a bit confused.
Thanks and expecting more suggestions
tony
-
I think ur using weblogic's PortableRemoteObject.Try
using javax.rmi.PortableRemoteObject.I assume ur using
browser,u need to pack this package javax.rmi and send it back to client inorder to use it.
Regards,
Vinoth.C