8 Replies Latest reply on Feb 12, 2007 9:13 PM by htran_888

    NameNotFoundException: DefaultDS not bound - Entity Unit (Ca

    htran_888

      Hi All,

      I have not been able to bind the default Hypersonic database (DefaultDS) in JBoss after having created a simple Entity class (Cabin) and a Persistent Unit (titanPU). Below is the listing from JBoss output:

      ---------------------------------------------------------------------------------------

      17:03:12,109 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=titan.jar,name=TravelAgentBean,service=EJB3 with dependencies:
      17:03:12,125 INFO [JmxKernelAbstraction] persistence.units:unitName=titan
      17:03:12,156 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.0.4.GA/server/default/deploy/titan.jar
      17:03:12,500 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
      17:03:14,125 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

      --- MBeans waiting for other MBeans ---
      ObjectName: persistence.units:jar=titan.jar,unitName=titanPU
      State: FAILED
      Reason: javax.naming.NameNotFoundException: DefaultDS not bound
      I Depend On:
      jboss.jca:service=ManagedConnectionFactory,name=DefaultDS

      ObjectName: jboss.j2ee:jar=titan.jar,name=TravelAgentBean,service=EJB3
      State: NOTYETINSTALLED
      I Depend On:
      persistence.units:unitName=titan

      --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
      ObjectName: persistence.units:unitName=titan
      State: NOTYETINSTALLED
      Depends On Me:
      jboss.j2ee:jar=titan.jar,name=TravelAgentBean,service=EJB3

      ObjectName: persistence.units:jar=titan.jar,unitName=titanPU
      State: FAILED
      Reason: javax.naming.NameNotFoundException: DefaultDS not bound
      I Depend On:
      jboss.jca:service=ManagedConnectionFactory,name=DefaultDS


      ---------------------------------------------------------------------------------------

      I do not have any difficulty creating the same EJB (Entity class - Cabin, Entity Unit - titan, Session bean - TravelAgent) using the supplied Ant script (build.xml) provided as part of EJB 3.0 Resource Workbook.

      Here is a comparison between the persistence.xml file that came with the exercise and the one produced by Netbeans:

      --------------------------------------------------------------------------------------
      <?xml version="1.0" encoding="UTF-8" ?>
      -
      - <persistence-unit name="titan">
      <jta-data-source>java:/DefaultDS</jta-data-source>
      -


      </persistence-unit>

      ################################################
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      <persistence-unit name="titanPU" transaction-type="JTA">
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>DefaultDS</jta-data-source>



      </persistence-unit>

      -------------------------------------------------------------------------------------

      Numerous searches on Google and forums have not been fruitful.

      I am running Netbeans 5.5 bundled with JBoss 4.0.4 on Windows 2000/XP.

      Many thanks,

      Henry

        • 1. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
          lkotouc

          Try to replace 'DefaultDS' by 'java:/DefaultDS' in persistence.xml.

          • 2. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
            htran_888

            Hi L,

            By prepending the "java:/" to DefaultDS in persistence.xml file did fixed the binding issue. I have tried this in the past but did not redeploy correctly. Anyhow, I now receive the following error when running the Client.java on the titan.jar EJB:

            javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
            at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
            at javax.naming.InitialContext.lookup(InitialContext.java:392)
            at client.Client.main(Client.java:31)


            Here is the code for Client.java:

            package client;

            import travelagent.TravelAgentRemote;
            import domain.Cabin;
            import java.util.Properties;
            import javax.naming.Context;
            import javax.naming.InitialContext;
            import javax.naming.NamingException;

            import javax.rmi.PortableRemoteObject;

            public class Client
            {
             public static void main(String [] args)
             {
             try
             {
             Context ctx = getInitialContext();
             Object ref = (TravelAgentRemote) ctx.lookup("TravelAgentRemote");
             TravelAgentRemote dao = (TravelAgentRemote)
             PortableRemoteObject.narrow(ref,TravelAgentRemote.class);
            
             Cabin cabin_1 = new Cabin();
             cabin_1.setId(1);
             cabin_1.setName("Master Suite");
             cabin_1.setDeckLevel(1);
             cabin_1.setShipId(1);
             cabin_1.setBedCount(3);
            
             dao.createCabin(cabin_1);
            
             Cabin cabin_2 = dao.findCabin(1);
             System.out.println(cabin_2.getName());
             System.out.println(cabin_2.getDeckLevel());
             System.out.println(cabin_2.getShipId());
             System.out.println(cabin_2.getBedCount());
            
             }
             catch (javax.naming.NamingException ne)
             {
             ne.printStackTrace();
             }
             }
            
             public static Context getInitialContext()
             throws javax.naming.NamingException
             {
             return new javax.naming.InitialContext();
             }
            }


            Thanks again,

            Henry


            • 3. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
              lkotouc

              You must initialize the context environment. The following code works with JBoss AS 4 (EJB2.1 module is deployed):


              package accessejb;

              import a.AccessibleSessionRemote;
              import a.AccessibleSessionRemoteHome;
              import java.util.Hashtable;
              import javax.naming.InitialContext;
              import javax.rmi.PortableRemoteObject;

              public class Main {

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

              AccessibleSessionRemote asr = lookupAccessibleSessionBean();
              String msg = asr.hello("World");
              System.out.println(msg);
              }

              private static AccessibleSessionRemote lookupAccessibleSessionBean() throws Exception {
              Object remote = getContext().lookup("AccessibleSessionBean");
              AccessibleSessionRemoteHome rv = (AccessibleSessionRemoteHome) PortableRemoteObject.narrow(remote, AccessibleSessionRemoteHome.class);
              return rv.create();
              }

              private static InitialContext getContext() throws Exception {
              Hashtable<String, String> env = new Hashtable<String, String>();
              env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
              env.put("java.naming.provider.url", "jnp://localhost:1099");
              return new InitialContext(env);
              }
              }



              Remote interface: a.AccessibleSessionRemote
              Home interface: a.AccessibleSessionRemoteHome

              The home interface is bound to 'AccessibleSessionBean' name.

              Following libraries must be on the classpath:
              /client/jboss-j2ee.jar
              /client/jbossall-client.jar
              /server/default/lib/jnpserver.jar
              /lib/jboss-common.jar

              • 4. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
                lkotouc

                [should have been in the previous reply]
                /client/jboss-j2ee.jar
                /client/jbossall-client.jar
                /server/default/lib/jnpserver.jar
                /lib/jboss-common.jar

                • 5. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
                  lkotouc

                  [server]/client/jboss-j2ee.jar
                  [server]/client/jbossall-client.jar
                  [server]/server/default/lib/jnpserver.jar
                  [server]/lib/jboss-common.jar

                  • 6. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
                    htran_888

                    Hi L,

                    Thanks for your suggestion and I will try to modify these EJB 2.1 syntax for my EJB 3.0 issue. However, I have the following questions:
                    ( i ) The code used was the same one that I have successfully compiled using the build.xml supplied as part of the EJB 3.0 Workbook (Bill Burke) on the command prompt. This means that it should not need further tampering/customisation to make it work. The only difference in this case is that I have used Netbeans to create this EJB that appears to have difficulty deploying properly. Received the following message when deploying the titan EJB using Netbeans to JBoss:

                    06:16:28,187 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
                    06:16:29,250 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

                    --- Incompletely deployed packages ---
                    org.jboss.deployment.DeploymentInfo@62fe5342 { url=file:/C:/jboss-4.0.4.GA/server/default/deploy/titan.jar }
                    deployer: MBeanProxyExt[jboss.ejb3:service=EJB3Deployer]
                    status: Deployment FAILED reason: Trying to install an already registered mbean: jboss.system:service=ThreadPool
                    state: FAILED
                    watch: file:/C:/jboss-4.0.4.GA/server/default/deploy/titan.jar
                    altDD: null
                    lastDeployed: 1170962187656
                    lastModified: 1170962187312
                    mbeans:


                    No Cabin table has been created either.
                    ( ii ) Could anyone assist me in translating those EJB 2.1 statements to EJB 3.0 since I am very new to EJB 3.0 and does not have a clue how EJB 2.1 work.

                    I will read up some Netbeans user guide/cheat sheet to ensure that the titan EJB is created properly, even though it is a very straight forward step.

                    Lastly, is it possible that I could not have both Glassfish (ASJS 9.0) & JBoss AS 4.0.4 co-existing on the same Windows XP platform?

                    I do appreciate very much for you helping me out on this issue.

                    Thanks,

                    Henry

                    • 7. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
                      lkotouc

                      The main problem results from inability to initialize the context, see the exception:
                      >Need to specify class name in environment or system property: java.naming.factory.initial

                      Some properties must be set prior to creation of InitialContext instance. The other way of setting the properties is to provide jndi.properties file along with your client code.

                      BTW, are you sure that the deployment exception comes from your jar? I am not sure about the meaning of the reason of the deployment failure:
                      >Trying to install an already registered mbean: jboss.system:service=ThreadPool
                      Does it appear even if you don't deploy your jar? If it does, the reason is not in your jar. If it doesn't, try to deploy as simple EJB module as possible (e.g. with one stateless session bean only) and modify/deploy it (to get the EJB module you use now) until the exception appears. This way you'll identify the problem.

                      Generally, get rid of the deployment exception first and then set the environment properties to initialize the context in the client code.

                      • 8. Re: NameNotFoundException: DefaultDS not bound - Entity Unit
                        htran_888

                        Hi L,

                        Success at last after having upgraded JBoss to 4.0.5 (full support for EJB 3.0) which may have fixed the problem. Anyhow the main sticking point was not referencing TravelAgentBean correctly using JNDI. Below is the only slight modification needed from the original code from the Client:

                        Context ctx = getInitialContext();
                         Object ref = (TravelAgentRemote) ctx.lookup("TravelAgentBean/remote");
                         TravelAgentRemote dao = (TravelAgentRemote)
                         PortableRemoteObject.narrow(ref,TravelAgentRemote.class);


                        or
                        InitialContext ctx = new InitialContext();
                         TravelAgentRemote dao = (TravelAgentRemote) ctx.lookup("TravelAgentBean/remote");


                        No need for any JNDI bootstraping properties as in EJB 2.1 or earlier.

                        Likewise, I didn't need these libraries in the Client's classpath either:

                        /client/jboss-j2ee.jar
                        /client/jbossall-client.jar
                        /server/default/lib/jnpserver.jar
                        /lib/jboss-common.jar.

                        I also learnt a lot on creating EJB using Netbeans & JBoss to lookup JNDI that was largely my problem.

                        Again a Big thank you for all your suggestions,

                        Henry