3 Replies Latest reply on May 18, 2007 2:19 PM by Donald Tyler

    NamingException: Could not dereference object - EJB 3.0 work

    Helen Tran Newbie

      Hi Everyone,

      I have stucked on workbook ex05_2 that makes comparison between using the same entity bean in TransactionPersistenceContext & ExtendedPersistenceContext. Anyhow, the following error occurred when trying to access either of these contexts:

      javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1150)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:705)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at client.Main.main(Main.java:33)
      Caused by: java.lang.reflect.UndeclaredThrowableException
      at $Proxy1.createProxy(Unknown Source)
      at org.jboss.ejb3.JndiProxyFactory.getObjectInstance(JndiProxyFactory.java:52)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1125)
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1142)
      ... 4 more

      This message make sense considering the jndi listing as follows:

      +- ExtendedPersistenceContextBean (class: org.jnp.interfaces.NamingContext)
      | +- remote (class: java.lang.Object)
      | +- remoteStatefulProxyFactory (proxy: $Proxy76 implements interface org.jboss.ejb3.ProxyFactory)
      +- TravelAgentBean (class: org.jnp.interfaces.NamingContext)
      | +- remote (proxy: $Proxy81 implements interface travelagent.TravelAgentRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
      +- TransactionPersistenceContextBean (class: org.jnp.interfaces.NamingContext)
      | +- remote (class: java.lang.Object)
      | +- remoteStatefulProxyFactory (proxy: $Proxy76 implements interface org.jboss.ejb3.ProxyFactory)


      To call TravelAgentRemote interface, use jndiContext.lookup("TravelAgentBean/remote"). However, it appears that
      I would not get anything by calling either jndiContext.lookup("TransactionPersistenceContextBean/remote") or jndiContext.lookup("ExtendedPersistenceContextBean/remote") according to the above jndi table.

      The client code are as follows:

      try
       {
       Context jndiContext = getInitialContext();
       Object ref = jndiContext.lookup("TravelAgentBean/remote");
       TravelAgentRemote dao = (TravelAgentRemote)ref;
      
       ref = jndiContext.lookup("TransactionPersistenceContextBean/remote");
       TransactionPersistenceContextRemote txBean = (TransactionPersistenceContextRemote)ref;
      
       Cabin fetchedCabin = dao.findCabin(1);
       int oldBedCount = fetchedCabin.getBedCount();
      
       System.out.println("Set up transaction persistence context stateful bean");
       txBean.setCabin(1);
       txBean.updateBedCount(5);
      
       ref = jndiContext.lookup("ExtendedPersistenceContextBean/remote");
       ExtendedPersistenceContextRemote extendedBean = (ExtendedPersistenceContextRemote)ref;
      
       extendedBean.setCabin(1);
       extendedBean.updateBedCount(5);
      ....

      This exercise does not work as delivered on the command prompt.

      I am running Netbeans 5.5, JBoss 4.0.5GA & JDK1.6.0 on Windows XP platform.

      The workbook is from EJB 3.0 by Bill Burke.

      Any assistance would be greatly appreciated.

      Thanks,

      Henry


        • 1. Re: NamingException: Could not dereference object - EJB 3.0
          Helen Tran Newbie

          Hi,

          I managed to overcome this issue by carrying out the the following changes which worked on Sun System Java Application Server PE 9.0 only:

          ( i ) Re-create a single titan ejb project to include all 3 session beans (TravelAgent, TransactionPersistenceContext, ExtendedPersistenceContext) & 1 entity class (Cabin) in one titan.jar file. More importantly, have all classes pointing to 1 persistence unit (titan).

          The persistence.xml file was the root to my problem.

          ( ii ) Re-create Client with these syntax:

          ref = jndiContext.lookup("travelagent.TransactionPersistenceContextRemote");
          ref = jndiContext.lookup("travelagent.ExtendedPersistenceContextRemote");


          As a result, the Client output from Netbeans is:

          no cabin should be null: null
          Master Suite
          1
          1
          3
          Updating detached cabin instance with new bed count of 4
          Finding cabin to see it has been updated with a merge() on server
          new bed count is: 4
          Set up transaction persistence context stateful bean
          Cabin bed count will still be 4: 4
          Set up extended persistence context stateful bean
          Cabin bed count will be 5: 5

          However, I still could not find a solution when running in JBoss AS 4.0.5.

          Thanks,

          Henry

          • 2. Re: NamingException: Could not dereference object - EJB 3.0
            Helen Tran Newbie

            Hi All,

            Could someone please help me with this issue?

            I still could not identify what the problem for so many weeks.

            Thanks,

            Henry

            • 3. Re: NamingException: Could not dereference object - EJB 3.0
              Donald Tyler Newbie

              Not sure if you managed to find a solution to this, but I'll post my experiences just in case.

              I had the same problem with exercise 11.4 & 11.5 running on JBoss 4.0.5.GA

              I managed to resolve the problem by upgrading to the recently released JBoss 4.2.0.GA