ClassCastException when Accessing an EJB Method from .NET Client |
|
Contents
- SYMPTOMS
- CAUSE
- RESOLUTION
SYMPTOMS
Following the Accessing EJBs from C# Using BEA Weblogic example, you've successfully deployed the EJB JAR file and servlet WAR file. When calling a method of the EJB that returns a Java object, a java.lang.ClassCastException is thrown, as shown below:
CAUSE
Calling a method from your .NET client on an EJB that returns a Java Object would require Ja.NET to do a cast. As such, there are two conflicting versions of the returned object, because different classloaders are being used. This is because the EJB JAR file is included with the WAR file, while the same JAR file is also deployed on the server.
RESOLUTION
When using the Janetor tool to create a WAR file, do not include the EJB JAR file in the "User Library" field. By doing this, you are ensuring that there is only one copy of the EJB JAR file existing on the server (the one that is deployed).
Note that the proper way of returning non-serializable objects from an EJB method call is to make the returned object an EJB also. Because JanetServlet is located on the same domain as the EJB, and consequently will be loaded in the same process, this is an exception to the rule. The returned object is not "remoted" and will not need to be a separate EJB.
Status
This issue does not require any fixes to J-Integra for .NET.