ClassCastException Using PortableRemoteObject

Discussions

EJB programming & troubleshooting: ClassCastException Using PortableRemoteObject

  1. ClassCastException Using PortableRemoteObject (1 messages)

    Hi!

    New at this.

    My problem is that I get a ClassCastException at the PortableRemoteObject call, I'm using the J2ee Server that comes with Sun J2EE JDK1.3. It did work at one stage but the code has not changed I did redeploy but I have checked that all is the same as previous deploy.

    It errors when the PortableRemoteObject trys to cast between serviceRef and serviceClass (serviceRef, serviceClass).

    I hate inserting this much code but I have to. Could someone help?

    Code Exert :
    _________________________________________________________
            public EJBObject getService(int service) {
            AnimalService animalService = null;
    String serviceName=null;
    Class serviceClass=null;

    switch(service) {
    case ANIMAL :
    serviceName = "AnimalService";
    serviceClass = AnimalServiceHome.class;
    }
            try {
                InitialContext initial = new InitialContext();
                java.lang.Object serviceRef = initial.lookup(serviceName);
                AnimalServiceHome animalServiceHome = (AnimalServiceHome)PortableRemoteObject.narrow(serviceRef, serviceClass); // Error here
                animalService = animalServiceHome.create();
            }
            catch (Exception ne) {
                System.out.println(e.getMessage());
            }
            return ((EJBObject)animalService);
        }
    __________________________________________________________
    Thanks in advance

    Glenn
  2. Ohhh this sounds familiar. Probably the error is generated due to different classloaders for your ejb/interface and the client. Try looking up the classloaders to be sure. I haven't yet found a nice solution to this problem :( Who has?
    I am running JBoss3.0 and Tomcat4.0 on two different jdk's, so as to make it easier to split it later on to two different machines.
    Jeroen