Discussions

EJB programming & troubleshooting: JBOSS EJB 3 JNDI Problem

  1. JBOSS EJB 3 JNDI Problem (4 messages)

    Hi all,
    I have recently attempted to connect to a stateful session bean on my jboss server that I created from the jboss tutorial.
    Their client I used (only with package name changes) gives me the following error:
    Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference
    at testEjb3.Client.main(Client.java:17)

    code for line 16-17:
    InitialContext ctx = new javax.naming.InitialContext();
    ShoppingCart cart = (ShoppingCart)ctx.lookup(ShoppingCart.class.getName());


    I use the eclipse jboss ide and jboss version 4.0.2

    I'm sure this is a classpath error. I was wondering if any one else had tried this example and what they put in their classpath.

    Threaded Messages (4)

  2. JBOSS EJB 3 JNDI Problem[ Go to top ]

    This happens to me too. Does this work for anyone?
  3. It seems there is a bug with JBoss 4.0.2. I deployed the same example ear file to version 4.0 and 4.0.2 but version 4.0.2 failed. When I lookuped the home of a bean deployed from a web servlet using InitialContext JBoss Server 4.0.2 always appended additional "Home" to the end of bound JNDI subcontext, which caused ClassCastException. The funny thing is, if you use stand-alone client there are no such exception at all.
  4. JBOSS EJB 3 JNDI Problem[ Go to top ]

    Same problem here:

    java.lang.ClassCastException: javax.naming.Reference
    at org.jboss.ejb3.LocalProxy.readObject(LocalProxy.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:919)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1813)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
    at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
    at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:57)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:637)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
    at javax.naming.InitialContext.lookup(InitialContext.java:351)
    at xxx.JNDITest.testJNDI(JNDITest.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
  5. Re: JBOSS EJB 3 JNDI Problem[ Go to top ]

    I found the same problem. As default, Session Bean is binding by ClassNameBean/local or ClassNameBean/remote. But if the aplliaction is deployed in .ear file then its binding by ear_name_file/Class_Name_bean/remote. example if our ear file is ojolali.ear and the Session Class name is BasoBean.class then its bind as ojolali/BasoBean/remote. but if its deploy in jar then to get the bean remote from JNDI is ; InitialContext ctx = new javax.naming.InitialContext(); ShoppingCart cart = (ShoppingCart)ctx.lookup(ShoppingCart.class.getName()+"/remote");