4 Replies Latest reply on May 14, 2003 9:43 AM by wpfeiffe

    Hibernate 2.0 jndi datasource lookup fails

    wpfeiffe

      I'm attempting to set up Hibernate 2.0 jmx service to work with JBoss 3.2.1. The service (deployed SAR) fails when it attempts to obtain ds connection via jndi. I have it configured to use the same jndi name my j2ee app uses (successfully!).

      The hibernate code appears to be doing the same thing my j2ee code is doing: gets the default InitialContext and does the lookup.

      Here's a snip of the error:

      2003-05-07 21:41:34,183 INFO [net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
      2003-05-07 21:56:10,684 FATAL [net.sf.hibernate.connection.DatasourceConnectionProvider] Could not find datasource: java:comp/env/espeed
      javax.naming.NameNotFoundException: env not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:606)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)

        • 1. Re: Hibernate 2.0 jndi datasource lookup fails
          davidjencks

          Look in jndi-view from the jmx console to find out what your datasource is bound under globally and use that. It will look like
          java:/myds without the comp/env part that you are currently using. There isn't a way to set up local references for mbeans so you will have to use the global jndi name.

          • 2. Re: Hibernate 2.0 jndi datasource lookup fails
            wpfeiffe

            After some experimentation, it appears that the hibernate.sar is loading before the datasource is bound. Is there a way to control the load order of the jmx modules (a dependancy setting perhaps)?

            Btw, only the global name worked.

            Thanks for your help!

            • 3. Re: Hibernate 2.0 jndi datasource lookup fails
              davidjencks

              If the Hibernate stuff is controlled by a mbean that follows the jboss service lifecycle, (has a start method, in which the jndi lookup occurs), then you can include a jboss.jca:service=TxCM,name=[the jndi name] element in the jboss-service.xml file in the .sar. Check the jmx console for the exact object name.

              If it just starts when created, the easiest thing to do is probably include the *-ds.xml in the .sar (at the root) With at least the most recent 3.0 and 3.2 it should get deployed, and first.

              You can also name your packages 1mydb-ds.xml, 2hibernate.sar etc and use the prefix deployment sorter.

              • 4. Re: Hibernate 2.0 jndi datasource lookup fails
                wpfeiffe

                Solved it with a depends element. Thanks for the help.