ClassCastExeption :stateless session bean call CMP entity bean

Discussions

EJB programming & troubleshooting: ClassCastExeption :stateless session bean call CMP entity bean

  1. Hi, there!

    I wrote a CMP Entity Bean in JBuilder5 and test it with the EJB's test client generated by the JBuilder's wizard,everything is ok! And then,I wrote a Stateless Session Bean to call that Entity Bean,at first ,I put the two beans in one project's one JAR file,it also works well.But when i put the two beans in two JAR files,still in one project,throws out the "ClassCastException",I don't know the reason,could you tell me?Thanks.

    my tool is JBuilder5 + Borland AppServer4.5.1
    the related infomation as follows:


    //get naming context Context ctx = new InitialContext(); //look up jndi name ,it's CabinJNDI;Object ref = ctx.lookup("CabinJNDI"); //cast to Home interface

    CabinHome cabinHome = (CabinHome) PortableRemoteObject.narrow(ref, CabinHome.class); //ErrorLine

    the server side error info as follows:

    >>>> EJB LOG >>>>

    Throwing java.rmi.RemoteException for the container-started transaction for method: public abstract java.lang.String[] titan.travelagent.TravelAgentRemote.listCabins(int,int) throws java.rmi.RemoteException java.rmi.ServerException: null; nested exception is: java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl at titan.travelagent.TravelAgentBean.listCabins(TravelAgentBean.java:42) at java.lang.reflect.Method.invoke(Native Method) at com.inprise.ejb.ConcreteMethod.invoke(ConcreteMethod.java:25) at com.inprise.ejb.EJBContext.invoke(EJBContext.java:129) at com.inprise.ejb.Dispatcher.doInvoke(Dispatcher.java:1055) at com.inprise.ejb.Dispatcher.invoke(Dispatcher.java:572) at com.inprise.ejb.Dispatcher.invoke(Dispatcher.java:548) at com.inprise.ejb.Dispatcher.invoke(Dispatcher.java:255) at titan.travelagent.TravelAgentRemotePOAInvokeHandler.listCabins(TravelAgentRemotePOAInvokeHandler.java:37) at titan.travelagent.TravelAgentRemotePOAInvokeHandler.listCabins(TravelAgentRemotePOAInvokeHandler.java:71) at titan.travelagent.TravelAgentRemotePOA._invoke(TravelAgentRemotePOA.java:64) at titan.travelagent.TravelAgentRemotePOA._invoke(TravelAgentRemotePOA.java:43) at com.inprise.vbroker.poa.POAImpl.invoke(POAImpl.java:2355) at com.inprise.vbroker.poa.ActivationRecord.invoke(ActivationRecord.java:104) at com.inprise.vbroker.poa.ServerInterceptorManager$ARWrapper.invoke(ServerInterceptorManager.java:64) at com.inprise.vbroker.GIOP.GiopProtocolAdapter.doRequest(GiopProtocolAdapter.java:492) at com.inprise.vbroker.IIOP.ServerProtocolAdapter.doRequest(ServerProtocolAdapter.java:64)


    EJB Container Statistics
    ========================
    TimeTue Oct 16 09:59:26 CST 2001
    Memory (used)1121 Kb(max 1121 Kb)
    Memory (total)2040 Kb(max 2040 Kb)
    Memory (free)45.0%
    ------------------------
    Home CabinJNDI
    Total in memory 0
    Total in use 0
    ------------------------
    Home TravelAgentJNDI
    KILLED1
    Total in memory 1
    Total in use 0
    ========================


    at com.inprise.vbroker.GIOP.GiopProtocolAdapter.dispatchMessage(GiopProtocolAdapter.java:653) at com.inprise.vbroker.orb.TPDispatcherImpl$TPDispatcher.run(TPDispatcherImpl.java:99) at com.inprise.vbroker.orb.ThreadPool$PoolWorker.run(ThreadPool.java:76)

    <EJB Container Statistics
    ========================
    TimeTue Oct 16 10:00:26 CST 2001
    Memory (used)1123 Kb(max 1123 Kb)
    Memory (total)2040 Kb(max 2040 Kb)
    Memory (free)44.0%
    ------------------------
    Home CabinJNDI
    Total in memory 0
    Total in use 0
    ------------------------
    Home TravelAgentJNDI
    FINALIZED 1
    Total in memory 0
    Total in use 0
    ========================

    the client side error as follows:


    java.rmi.ServerException: ; nested exception is: java.rmi.RemoteException: null; nested exception is: java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl; nested exception is: java.rmi.ServerException: null; nested exception is: java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl java.rmi.RemoteException: null; nested exception is: java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl; nested exception is: java.rmi.ServerException: null; nested exception is: java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl java.rmi.ServerException: null; nested exception is: java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl java.lang.ClassCastException: com.inprise.vbroker.rmi.CORBA.ObjectImpl <
  2. I have the same error, did u solve it?
  3. Apparently, the client jar must be in the classpath during execution.

  4. I've run into it too, and did some research both in my application and on the internet. My situation was that I was calling my EJB in Jboss, from a servlet in Tomcat, and I got a ClassCastException, when doing the PortableRemoteObject cast. The reason is that your container and client CAN use different classloaders when they're not in the same jar/ear/war.
    I solved this by using two JDK's, one for jboss, and one for Tomcat. The tomcat one has a lot of extra jars in the jdk/jre/lib/ext folder, amongst others all JBoss jars, and my application jar. This is a very crude solution but it works. Who has a better solution than the one presented??

    Jeroen