views:

45

answers:

1

I have 2 ejbs. Ejb-A that calls Ejb-B. They are not in the same Ear.

For portability Ejb-B may or may not exist on the same server. (There is an external property file that has the provider URLs of Ejb-B. I have no control over this.)

Example Code: in Ejb-A

EjbBDelegate delegateB = EjbBDelegateHelper.getRemoteDelegate(); // lookup from list of URLs from props... 
BookOfMagic bom = delegateB.getSomethingInteresting();

Use Cases/Outcomes:

  1. When Ejb-B DOES NOT EXIST on the same server as Ejb-A, everything works correctly. (it round-robbins through the URLs)
  2. When Ejb-B DOES EXIST on the same server, and Ejb-A happens to call Ejb-B on the same server, everything works correctly.
  3. When Ejb-B DOES EXIST on the same server, and Ejb-A calls Ejb-B on a different server, I get:

javax.ejb.EJBException: nested exception is: java.lang.ClassCastException: $Proxy126 java.lang.ClassCastException: $Proxy126

I'm using Weblogic 10.0, Java 5, EJB3

Basically, if Ejb-B Exists on the server, it must be called ONLY on that server.

Which leads me to believe that the class is getting loaded by a local classloader (on deployment?), then when called remotely, a different classloader is loading it. (causing the Exception) But it should work, as it should be Serialized into the destination classloader...

What am I doing wrong??

Also, when reproducing this locally, Ejb-A would favor the Ejb-B on the same server, so it was difficult to reproduce. But this wasn't the case on other machines.

NOTE: This all worked correctly for EJB2

A: 

So I was able to 'fix' this issue by adding a @RemoteHome(MyRemoteHome.class) to the bean

public interface MyRemoteMethods {
    String myMethod() throws RemoteException; // this Ex is required
}

public interface MyRemote extends EJBObject, MyRemoteMethods { 
}

public interface MyRemoteHome extends EJBHome {
    public MyRemote create() throws CreateException, RemoteException;
}

then my bean

...
@RemoteHome(MyRemoteHome.class)
public class MyBean implements MyRemoteMethods {
...

Previously, only the bean and the Remote interface existed. (there is no local usage)

Overall, this fix makes my EJB 3 a bit more EJB 2-ish and not as clean (more code and classes involved). I am also unclear why I can do a jndi lookup for the RemoteHome interface (and call create) from my local and remote servers and not get a ClassCastException, but when I do this for the Remote interface, I do get a ClassCastException. Is this a bug in Weblogic? (I've also seen some posts similar using JBoss)

aaronvargas