1 Reply Latest reply on Apr 29, 2004 10:14 PM by plainkeyman

    Datasource not available -- please help

    plainkeyman

      I've got some jsp's that need to communicate with a database and some ejb's. The ejb needs to also connect to the database.

      The jsp's can connect to the database, and they can connect to the ejb's. But when the ejb tries to find the database, it says it's not bound.

      How do i get my ejb to see the database?

      ejb-jar.xml

      <ejb-jar>
       <enterprise-beans>
       <session>
       <ejb-name>repairs</ejb-name>
       <home>com.company.intranet.managers.repairsmaintenance.RepairsHome</home>
       <remote>com.company.intranet.managers.repairsmaintenance.Repairs</remote>
       <ejb-class>com.company.intranet.managers.repairsmaintenance.RepairsBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Bean</transaction-type>
       </session>
       </enterprise-beans>
      </ejb-jar>



      jboss.xml
      <jboss>
      
       <enterprise-beans>
       <entity>
       <ejb-name>repairs</ejb-name>
       <jndi-name>ejb/company/intranet/repairs</jndi-name>
       <local-jndi-name>ejb/company/intranet/repairs</local-jndi-name>
       </entity>
       </enterprise-beans>
      
       <resource-managers>
       <resource-manager res-class="">
       <res-name>pickledBrains</res-name>
       <res-jndi-name>java:comp/env/jdbc/mysql</res-jndi-name>
       </resource-manager>
       </resource-managers>
      </jboss>
      


      mysql-ds.xml
      <datasources>
       <local-tx-datasource>
       <jndi-name>jdbc/mysql</jndi-name>
       <connection-url>jdbc:mysql://192.168.1.201:3306/intranet</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>user</user-name>
       <password>pass</password>
       </local-tx-datasource>
      </datasources>
      


      relevant portion of web.xml
       <resource-ref>
       <description>db ref for intranet</description>
       <res-ref-name>jdbc/intranet</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Application</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>
      



      relevant portion of jboss-web.xml
       <resource-ref>
       <res-ref-name>jdbc/intranet</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <jndi-name>java:/jdbc/mysql</jndi-name>
       </resource-ref>
       <ejb-ref>
       <ejb-ref-name>ejb/company/intranet/repairs</ejb-ref-name>
       <jndi-name>ejb/company/intranet/repairs</jndi-name>
       </ejb-ref>
      





      and my JndiView results:
      Ejb Module: company-repairsMaintenance.jar
      
      java:comp namespace of the repairs bean:
      
       +- UserTransaction (class: javax.transaction.UserTransaction)
       +- env (class: org.jnp.interfaces.NamingContext)
      
      
      java: Namespace
      
       +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
       +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
       +- DefaultJMSProvider (class: org.jboss.jms.jndi.JBossMQProvider)
       +- comp (class: javax.naming.Context)
       +- jdbc (class: org.jnp.interfaces.NamingContext)
       | +- mysql (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
       +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
       +- jaas (class: javax.naming.Context)
       | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- Foodland-Intranet (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
       +- timedCacheFactory (class: javax.naming.Context)
      Failed to lookup: timedCacheFactory, errmsg=null
       +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
       +- Mail (class: javax.mail.Session)
       +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
       +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
       +- TransactionManager (class: org.jboss.tm.TxManager)
      
      
      Global JNDI Namespace
      
       +- jmx (class: org.jnp.interfaces.NamingContext)
       | +- invoker (class: org.jnp.interfaces.NamingContext)
       | | +- RMIAdaptor (proxy: $Proxy17 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor)
       | +- rmi (class: org.jnp.interfaces.NamingContext)
       | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
       +- OIL2XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- UserTransactionSessionFactory (proxy: $Proxy10 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
       +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- invokers (class: org.jnp.interfaces.NamingContext)
       | +- 0.0.0.0 (class: org.jnp.interfaces.NamingContext)
       | | +- pooled (class: org.jboss.invocation.pooled.interfaces.PooledInvokerProxy)
       | +- comp.comp.net (class: org.jnp.interfaces.NamingContext)
       | | +- jrmp (class: org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy)
       | | +- http (class: org.jboss.invocation.http.interfaces.HttpInvokerProxy)
       +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
       +- UILXAConnectionFactory[link -> UIL2XAConnectionFactory] (class: javax.naming.LinkRef)
       +- RMIXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- UIL2XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- topic (class: org.jnp.interfaces.NamingContext)
       | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
       | +- testTopic (class: org.jboss.mq.SpyTopic)
       | +- securedTopic (class: org.jboss.mq.SpyTopic)
       +- queue (class: org.jnp.interfaces.NamingContext)
       | +- A (class: org.jboss.mq.SpyQueue)
       | +- testQueue (class: org.jboss.mq.SpyQueue)
       | +- ex (class: org.jboss.mq.SpyQueue)
       | +- DLQ (class: org.jboss.mq.SpyQueue)
       | +- D (class: org.jboss.mq.SpyQueue)
       | +- C (class: org.jboss.mq.SpyQueue)
       | +- B (class: org.jboss.mq.SpyQueue)
       +- console (class: org.jnp.interfaces.NamingContext)
       | +- PluginManager (proxy: $Proxy18 implements interface org.jboss.console.manager.PluginManagerMBean)
       +- UIL2ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- UILConnectionFactory[link -> UIL2ConnectionFactory] (class: javax.naming.LinkRef)
       +- RMIConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- ejb (class: org.jnp.interfaces.NamingContext)
       | +- company (class: org.jnp.interfaces.NamingContext)
       | | +- intranet (class: org.jnp.interfaces.NamingContext)
       | | | +- repairs (proxy: $Proxy43 implements interface com.company.intranet.managers.repairsmaintenance.RepairsHome,interface javax.ejb.Handle)
       +- OIL2ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
      


      my ejb tries a lookup:
      Context ic = new InitialContext();
       Object obj = ic.lookup("pickledBrains");


      but every time:
      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: jdbc not bound]
      




      shouldn't i see 'pickledBrains' somewhere in my jndiview at least?


        • 1. Re: Datasource not available -- please help
          plainkeyman

          well ok -- i figured it out -- don't know what i was smokin'

          ejb-jar.xml:

          <ejb-jar>
           <enterprise-beans>
           <session>
           <ejb-name>repairs</ejb-name>
           <home>com.company.intranet.managers.repairsmaintenance.RepairsHome</home>
           <remote>com.company.intranet.managers.repairsmaintenance.Repairs</remote>
           <ejb-class>com.company.intranet.managers.repairsmaintenance.RepairsBean</ejb-class>
           <session-type>Stateless</session-type>
           <transaction-type>Bean</transaction-type>
          
           <resource-env-ref>
           <resource-env-ref-name>datasource</resource-env-ref-name>
           <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
           </resource-env-ref>
           </session>
           </enterprise-beans>
          </ejb-jar>
          




          jboss.xml
          <jboss>
           <enterprise-beans>
           <session>
           <ejb-name>repairs</ejb-name>
           <jndi-name>ejb/foodland/intranet/repairs</jndi-name>
           <local-jndi-name>ejb/foodland/intranet/repairs</local-jndi-name>
          
           <resource-env-ref>
           <resource-env-ref-name>datasource</resource-env-ref-name>
           <jndi-name>java:jdbc/mysql</jndi-name>
           </resource-env-ref>
          
           </session>
           </enterprise-beans>
          </jboss>
          


          and by looking up java:comp/env/datasource -- got me 'ol database....

          thanx to those who looked at my problem ;)