java.lang.ClassCastException in ejbLoad()


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

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

     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:
            at javax.rmi.CORBA.Util.mapSystemException(
            at ejbtest._Account_Stub.getBalance(Unknown Source)
            at ejbtest.AccountClient.main(
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(
            at java.lang.reflect.Method.invoke(
            at com.sun.enterprise.util.Utility.invokeApplicationMain(
            at com.sun.enterprise.appclient.Main.main(
    Caused by: java.rmi.RemoteException: nested exception is: java.lang.ClassCastException; nested exception is:
            at com.sun.enterprise.iiop.POAProtocolMgr.mapException(
            at com.sun.ejb.containers.BaseContainer.postInvoke(
            at ejbtest.AccountBean_EJBObjectImpl.getBalance(
            at ejbtest._AccountBean_EJBObjectImpl_Tie._invoke(Unknown Source)
    Caused by: java.lang.ClassCastException
            at ejbtest.AccountBean.ejbLoad(
            at com.sun.ejb.containers.EntityContainer.callEJBLoad(
            at com.sun.ejb.containers.EntityContainer.afterBegin(
            at com.sun.ejb.containers.BaseContainer.startNewTx(
            at com.sun.ejb.containers.BaseContainer.preInvokeTx(
            at com.sun.ejb.containers.BaseContainer.preInvoke(
            at ejbtest.AccountBean_EJBObjectImpl.getBalance(
            ... 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

  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 ]

     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.