File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Error while calling EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Error while calling EJB" Watch "Error while calling EJB" New topic
Author

Error while calling EJB

aadhar sharma
Ranch Hand

Joined: Oct 09, 2006
Posts: 38
Hi,

I am creating a stateless session bean using JBoss 4 server and JDK 6.0

I receive the folowing error when I try to call the EJb from my Java Application

below is the trace i have attached my jboss.xml jndi and ejb-jar.xml.


Exception in thread "main" javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.ejb3.session.BaseSessionRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 8310915813626447181, local class serialVersionUID = 2609262789016232311]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(Unknown Source)
at client.Client.main(Client.java:26)
Caused by: java.io.InvalidClassException: org.jboss.ejb3.session.BaseSessionRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 8310915813626447181, local class serialVersionUID = 2609262789016232311
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:652)
... 3 more




<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<description>JBoss Stateless Session Bean Tutorial</description>
<display-name>JBoss Stateless Session Bean Tutorial</display-name>
<enterprise-beans>
<session>
<ejb-name>Calculator</ejb-name>
<remote>statelessExamples.CalculatorRemote</remote>
<local>statelessExamples.CalculatorLocal</local>
<ejb-class>statelessExamples.CalculatorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>



<?xml version="1.0"?>
<jboss
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
version="3.0">
<enterprise-beans>
<session>
<ejb-name>Calculator</ejb-name>
<jndi-name>statelessExamples.CalculatorRemote</jndi-name>
<local-jndi-name>statelessExamples.CalculatorLocal</local-jndi-name>
</session>
</enterprise-beans>
</jboss>




package client;

import java.util.Properties;

import javax.naming.InitialContext;

import stateless.Calculator;
import stateless.CalculatorRemote;

public class Client {
public static void main(String[] args) throws Exception {

Properties p = new Properties();
p.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
p.put("java.naming.factory.url.pkgs",
"org.jboss.naming rg.jnp.interfaces");
p.put("java.naming.provider.url", "localhost:1099");

// System.setProperty("java.naming.factory.initial",
// "org.jnp.interfaces.NamingContextFactory");
// System.setProperty("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
// System.setProperty("java.naming.provider.url", "localhost:1099");

InitialContext ctx = new InitialContext(p);
Calculator calculator = (Calculator) ctx.lookup("statelessExamples.CalculatorRemote");

System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1));
}
}



Thanks and Regards

Aadhar Sharma


Thanks and Regards
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10263
    
168

Looks like you have incorrect JBoss jar files in the classpath of the client. You should have the same JBoss jar files as what you have on the server. Copy the jbossall-client.jar file from the %JBOSS_HOME%/client folder to your application's (client's) classpath and remove the other JBoss jar files.


[My Blog] [JavaRanch Journal]
aadhar sharma
Ranch Hand

Joined: Oct 09, 2006
Posts: 38
Thanks a Ton Jai

Worked out for me
Kelly Wei
Greenhorn

Joined: Feb 24, 2008
Posts: 1
It fixed it for me too!

Basically the client application needs the jbossall-client.jar from the jboss server that the ejbs are deployed under. I had multiple JBoss instances so that make it hard to find out what was wrong.

You da man!

BTW, Aadhar, I didn't have to put anything in jboss.xml and ejb-jar.xml, all I did was this:



http://docs.jboss.org/ejb3/app-server/tutorial/jndibinding/jndi.html
[ February 24, 2008: Message edited by: Kelly Wei ]
Jenny George
Greenhorn

Joined: May 13, 2005
Posts: 16
Worked for me too. Thanks


"Knowledge is proud that she knows so much; wisdom is humble that she knows no more."
B Misra
Greenhorn

Joined: Jul 27, 2007
Posts: 22
This thread helped me to solve some problems , but I am reviving this old post because-
Though getting the same jboss jar file in client as from server solved the issue , I am confused with the reason of this.
someone please through some light why is it so much dependent on server jars for a remote jndi lookup.
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 189
Because Client and Server communicate via serialized objects they need the same version of certain classfiles. The exception you got is about two different versions (detected via serialVersionUID).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while calling EJB