ClassCastException When Calling an EJB Remotely that Exists on Same Server
- by aaronvargas
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:
When Ejb-B DOES NOT EXIST on the same server as Ejb-A, everything works correctly. (it round-robbins through the URLs)
When Ejb-B DOES EXIST on the same server, and Ejb-A happens to call Ejb-B on the same server, everything works correctly.
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