4 Replies Latest reply on May 19, 2008 6:04 PM by Julian Gaertner

    NameNotFoundException: Datasource not bound

    Julian Gaertner Newbie

      Hi,


      I try to deploy an empty seam gen project on a Tomcat 6.0.16  using Seam
      2.0.2.GA and an HSQLDB.
      As I do not need any EJB-functionality I am not using JBoss Embaddable,
      but a plain Tomcat.


      I successfully tested the seam-booking example on my
      Tomcat-configuration but I'm having huge trouble deploying the seam gen
      projekt on my tomcat.


      As you can see in the following exception, the Datasource is not bound.
      My datasource-config is alright. Once I uncomment the seam
      servlet-listern and the seam filters, the tomcat starts up and the
      datasource is accessible.


      I guess that Tomcat/seam tries to access the Datasource too early on the
      server startup, which causes the failure. I'm stucked, could anyone
      please help me?


      I couldn't find any solution for my problen in this forum or on google...


      Regards
      Julian



      16.05.2008 13:03:40 org.jboss.seam.contexts.Contexts startup
      INFO: starting up: org.jboss.seam.security.facesSecurityEvents
      16.05.2008 13:03:40 org.jboss.seam.contexts.Contexts startup
      INFO: starting up: OnlineZeiterfassungEntityManagerFactory
      16.05.2008 13:03:40 org.hibernate.cfg.annotations.Version <clinit>
      INFO: Hibernate Annotations 3.3.0.GA
      16.05.2008 13:03:40 org.hibernate.cfg.Environment <clinit>
      INFO: Hibernate 3.2.4.sp1
      16.05.2008 13:03:40 org.hibernate.cfg.Environment <clinit>
      INFO: hibernate.properties not found
      16.05.2008 13:03:40 org.hibernate.cfg.Environment buildBytecodeProvider
      INFO: Bytecode provider name : cglib
      16.05.2008 13:03:40 org.hibernate.cfg.Environment <clinit>
      INFO: using JDK 1.4 java.sql.Timestamp handling
      16.05.2008 13:03:40 org.hibernate.ejb.Version <clinit>
      INFO: Hibernate EntityManager 3.3.1.GA
      16.05.2008 13:03:42 org.hibernate.util.NamingHelper getInitialContext
      INFO: JNDI InitialContext properties:{}
      16.05.2008 13:03:42
      org.hibernate.connection.DatasourceConnectionProvider configure
      SCHWERWIEGEND: Could not find datasource:
      global/OnlineZeiterfassungDatasource
      javax.naming.NameNotFoundException: Name global is not bound in this Context
          at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
          at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
          at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
          at javax.naming.InitialContext.lookup(InitialContext.java:392)
          at
      org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
          at
      org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
          at
      org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
          at
      org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
          at
      org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
          at
      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
          at
      org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
          at
      org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
          at
      org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
          at
      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
          at
      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
          at
      org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
          at
      org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.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:597)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
          at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
          at org.jboss.seam.Component.callComponentMethod(Component.java:2100)
          at org.jboss.seam.Component.callCreateMethod(Component.java:2015)
          at org.jboss.seam.Component.newInstance(Component.java:1976)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
          at
      org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
          at org.jboss.seam.init.Initialization.init(Initialization.java:596)
          at
      org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
          at
      org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
          at
      org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at
      org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
          at
      org.apache.catalina.core.StandardService.start(StandardService.java:516)
          at
      org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
          at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
          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:597)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      16.05.2008 13:03:42 org.apache.catalina.core.StandardContext listenerStart
      SCHWERWIEGEND: Exception sending context initialized event to listener
      instance of class org.jboss.seam.servlet.SeamListener
      org.jboss.seam.InstantiationException: Could not instantiate Seam
      component: OnlineZeiterfassungEntityManagerFactory
          at org.jboss.seam.Component.newInstance(Component.java:1986)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
          at
      org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
          at org.jboss.seam.init.Initialization.init(Initialization.java:596)
          at
      org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
          at
      org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
          at
      org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at
      org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
          at
      org.apache.catalina.core.StandardService.start(StandardService.java:516)
          at
      org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
          at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
          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:597)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      Caused by: javax.persistence.PersistenceException:
      org.hibernate.HibernateException: Could not find datasource
          at
      org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
          at
      org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
          at
      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
          at
      javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
          at
      org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
          at
      org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.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:597)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
          at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
          at org.jboss.seam.Component.callComponentMethod(Component.java:2100)
          at org.jboss.seam.Component.callCreateMethod(Component.java:2015)
          at org.jboss.seam.Component.newInstance(Component.java:1976)
          ... 20 more
      Caused by: org.hibernate.HibernateException: Could not find datasource
          at
      org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
          at
      org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
          at
      org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
          at
      org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
          at
      org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
          at
      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
          at
      org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
          at
      org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
          ... 34 more
      Caused by: javax.naming.NameNotFoundException: Name global is not bound
      in this Context
          at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
          at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
          at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
          at javax.naming.InitialContext.lookup(InitialContext.java:392)
          at
      org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
          ... 41 more
      16.05.2008 13:03:42 org.apache.catalina.core.StandardContext start
      SCHWERWIEGEND: Error listenerStart
      16.05.2008 13:03:42 org.apache.catalina.core.StandardContext start
      SCHWERWIEGEND: Context [/OnlineZeiterfassung2] startup failed due to
      previous errors
      16.05.2008 13:03:43 org.apache.coyote.http11.Http11Protocol start
      INFO: Starting Coyote HTTP/1.1 on http-8080
      16.05.2008 13:03:43 org.apache.jk.common.ChannelSocket init
      INFO: JK: ajp13 listening on /0.0.0.0:8009
      16.05.2008 13:03:43 org.apache.jk.server.JkMain start
      INFO: Jk running ID=0 time=0/219  config=null
      16.05.2008 13:03:43 org.apache.catalina.startup.Catalina start
      INFO: Server startup in 18388 ms
      


        • 1. Re: NameNotFoundException: Datasource not bound
          Jay Balunas Novice

          Some quick questions for you.


          What seam-booking example?  You said you do not have embedded installed - and the standard examples/booking example need it. 


          Also I'm assuming that you used war setup for your app - correct?


          Also from the exception it is not finding global so it is not even getting to your /OnlineZeiterfassungDatasource namespace.


          tomcat6 JNDI docs talks about needed to set resource link to expose this to the web app.




          Tomcat 6 maintains a separate namespace of global resources for the entire server. These are configured in the <GlobalNameingResources> element of $CATALINA_HOME/conf/server.xml. You may expose these resources to web applications by using <ResourceLink> elements.


          Hope this helps,


          Jay


          • 2. Re: NameNotFoundException: Datasource not bound
            Julian Gaertner Newbie

            Hi Jay,


            thank you for your quick reply. I used the jboss-seam-jpa example in my previous trial.


            You're assuming right. In the current project I used a war file to setup my app with seam gen. I already had a look on the Tomcat 6 JNDI docs and I recon that my datasource setup is alright. I configured the datasource as a ressource in the GlobalNamingResources section and used a ResourceLink in the Context section below.


            I can access the datasource with lambdaprobe, when I start up the tomcat without the seam listners and filters. That's why I am assuming that the datasource configuration should be alright. What is your opinion?
            You may have a look at the following extracts of my config files...


            Julian


            persistence.xml:




            <?xml version="1.0" encoding="UTF-8"?>
            <!-- Persistence deployment descriptor for dev profile -->
            <persistence 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" 
                         version="1.0">
                         
               <persistence-unit name="OnlineZeiterfassung" transaction-type="RESOURCE_LOCAL">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>global/OnlineZeiterfassungDatasource</jta-data-source>
                  <properties>
                     <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="hibernate.format_sql" value="true"/>
                    <!-- <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>  -->
                  </properties>
               </persistence-unit>
                
            </persistence> 





            Extracts from the server.xml:


                 <GlobalNamingResources>
                      <!-- Editable user database that can also be used by
                           UserDatabaseRealm to authenticate users
                      -->
                      <Resource auth="Container"
                           description="User database that can be updated and saved"
                           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                           name="UserDatabase" pathname="conf/tomcat-users.xml"
                           type="org.apache.catalina.UserDatabase" />
                      <Resource auth="Container"
                           driverClassName="org.hsqldb.jdbcDriver" maxActive="100" maxIdle="30"
                           maxWait="10000" name="global/OnlineZeiterfassungDatasource"
                           type="javax.sql.DataSource" url="jdbc:hsqldb:hsql://localhost/xdb"
                           username="sa" />
                 </GlobalNamingResources>
            
            ...
            
            
                    <Context docBase="OnlineZeiterfassung2"
                           path="/OnlineZeiterfassung2" reloadable="true"
                           source="org.eclipse.jst.jee.server:OnlineZeiterfassung2">
                           <ResourceLink name="global/OnlineZeiterfassungDatasource"
                                global="jdbc/OnlineZeiterfassungDatasource"
                                type="javax.sql.DataSource" />
                    </Context>




            I tried both ways, with and with-out a res-ref-name for the datasource in the web.xml: (It makes no difference)


            </web-app>
            ...
            
               </security-constraint>
            
              <resource-ref>
                  <description>DB Connection</description>
                  <res-ref-name>global/OnlineZeiterfassungDatasource</res-ref-name>
                  <res-type>javax.sql.DataSource</res-type>
                  <res-auth>Container</res-auth>
              </resource-ref> 
               
               
            </web-app>



            • 3. Re: NameNotFoundException: Datasource not bound
              Jay Balunas Novice

              Ok I think this is it.


              From the tomcat docs the references are all relative to java:comp/env and if you look at the JPA examples /jpa/resources-tomcat/META-INF/persistence.xml  it is using:


              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
              



              Try changing your persistence.xml to use paths relative to java:comp/env/.


              -Jay

              • 4. Re: NameNotFoundException: Datasource not bound
                Julian Gaertner Newbie

                Thanks Jay,


                my problem is solved.  You were right with the JNDI tree which has to be relative to java:comp/env/.


                My second failure has neen in the ResourceLink tag. The name is automatically relative to java:comp/env/. Thats's why I had to change it from


                name="java:comp/env/OnlineZeiterfassungDatasource



                to


                name="OnlineZeiterfassungDatasource




                The global value links to the global resource in the global JNDI context. That is why it has to have the                                   java:comp/env context.




                global="java:comp/env/OnlineZeiterfassungDatasource




                               <Context docBase="OnlineZeiterfassung2"
                                    path="/OnlineZeiterfassung2" reloadable="true"
                                    source="org.eclipse.jst.jee.server:OnlineZeiterfassung2">
                
                                    <ResourceLink
                                         name="OnlineZeiterfassungDatasource"
                                         global="java:comp/env/OnlineZeiterfassungDatasource"
                                         type="javax.sql.DataSource" />
                
                               </Context>





                Furthermore I had to add the entity transaction to the components.xml


                   <transaction:entity-transaction entity-manager="#{entityManager}"/>




                Thanks again Jay, I'm really happy to have a running blank project now...


                Julian