java.lang.ClassCastException in ejbLoad()

Discussions

EJB programming & troubleshooting: java.lang.ClassCastException in ejbLoad()

  1. java.lang.ClassCastException in ejbLoad() (4 messages)

    Hi
     I am new to this EJB concept and trying out the examples in Mastering EJB 2.0 book by Ed Roman.While executing the Account Entity Bean example gievn in chapter 6 I am getting the following exception in the ejbLoad() method in the following line
      AccountPK pk = (AccountPK) ctx.getPrimaryKey();
    The exception is given below:-
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            java.rmi.RemoteException: nested exception is: java.lang.ClassCastException; nested exception is:
            java.lang.ClassCastException
            at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:59)
            at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
            at ejbtest._Account_Stub.getBalance(Unknown Source)
            at ejbtest.AccountClient.main(AccountClient.java:43)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:229)
            at com.sun.enterprise.appclient.Main.main(Main.java:155)
    Caused by: java.rmi.RemoteException: nested exception is: java.lang.ClassCastException; nested exception is:
            java.lang.ClassCastException
            at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:389)
            at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:431)
            at ejbtest.AccountBean_EJBObjectImpl.getBalance(AccountBean_EJBObjectImpl.java:152)
            at ejbtest._AccountBean_EJBObjectImpl_Tie._invoke(Unknown Source)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:515)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:205)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:107)
            at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:250)
            at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:79)
            at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:104)
    Caused by: java.lang.ClassCastException
            at ejbtest.AccountBean.ejbLoad(AccountBean.java:89)
            at com.sun.ejb.containers.EntityContainer.callEJBLoad(EntityContainer.java:1632)
            at com.sun.ejb.containers.EntityContainer.afterBegin(EntityContainer.java:848)
            at com.sun.ejb.containers.BaseContainer.startNewTx(BaseContainer.java:1119)
            at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:1030)
            at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:375)
            at ejbtest.AccountBean_EJBObjectImpl.getBalance(AccountBean_EJBObjectImpl.java:146)
            ... 7 more
    i am running the program in Sun One Studio with Windows 2000.
  2. Are you calling from a java stand alone ...if that is the case you need to copy the jar you created and set the path to that jar before you compile the java stand alone client

    shiva
  3. Hello Mr. Shivashankar Krishnan
      First thing to tell you that... yes, I am using standalone client. For the rest part, can you tell me in detail like about which jar you are speaking of, where to copy it, and how to set that path to the jar you are speaking of.
    Actually, I am using Sun One Studio IDE... doesn't it do the things autoamtically. If not, do you know what to do in the IDE to set the path.
    Lastly, I am new to this ejb technology.So, please take the pain to explain me in a bit detail. I will be grateful.
    Thank You
  4. Please check the PrimaryKeyClass name in ejb-jar.xml it should be your AccountPK class.
  5. problem has been solved[ Go to top ]

    hi,
     the problem has been solved. There was an error in my ejbFindByOwnerName() method, instead of returning a vector containing the AccountPK classes, I was returning a vector containing string.
     Thank you everybody (specially Shiva and Kiran) for sharing your time and knowledge with me.