2 Replies Latest reply on Mar 27, 2009 10:57 AM by bai yong

    java.lang.RuntimeException: mapped-name is required for jdbc

    Jérôme Droz Newbie

      Hi,

      I'm new to jBoss AS and I'm trying to migrate a web application that almost worked on Tomcat 6.0.16 to jBoss 5 Beta4. The reason is that I realized Tomcat currently doesn't support resource injection and is somehow buggy... The application uses JPA to access one database and a datasource taken out from JNDI to access another database (but no other types of EJBs). The problem occurs when deploying the web archive:

      09:02:31,896 ERROR [BaseModelMBean] Exception invoking method addChild
      java.lang.RuntimeException: mapped-name is required for jdbc/[my-jndi-name] of deployment [my-war]
       at org.jboss.injection.ResourceHandler.loadXmlResourceRefs(ResourceHandler.java:156)
       at org.jboss.injection.ResourceHandler.loadXml(ResourceHandler.java:270)
       at org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(TomcatInjectionContainer.java:348)
      ...
      


      I followed jBoss's guide to configure a data source in an xml file named mysql-ds.xml (in the "deploy" directory) that looks like this:

      <datasources>
       <local-tx-datasource>
       <jndi-name>jdbc/[my-jndi-name]</jndi-name>
       <connection-url>jdbc:mysql://[my-host]:3306/[my-db]</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>[my-username]</user-name>
       <password>[my-password]</password>
       <min-pool-size>5</min-pool-size>
       <max-pool-size>20</max-pool-size>
       <idle-timeout-minutes>5</idle-timeout-minutes>
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
       <new-connection-sql>SELECT 1</new-connection-sql>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      


      I've also add the following fragment to the web.xml file:

      <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/[my-jndi-name]</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>
      


      I found some documentation about mapped-name in the J2EE API docs, in the @Resource annotation class... but I'm confused about its usage. Do I have to use resource injection in order to make it work? Because that's not the case... I'm using plain JNDI coding:

      ...
      Context initialContext = new InitialContext();
      DataSource dataSource = (DataSource)initialContext.lookup(JNDI_CONNECTION_NAME);
      connection = dataSource.getConnection();
      ...
      


      Is there something obvious I'm missing? Do I have to configure an ejb-jar.xml and refactor my code to exclusively use stateless Beans and resource injection?

      Any help will be appreciated.

      Thanks,
      Jerome

        • 1. Re: java.lang.RuntimeException: mapped-name is required for
          Jérôme Droz Newbie

          OK, the problem was quite simple to solve: I added an element named "mapped-name" as a child of the "resource-ref" element in the web.xml...

          • 2. Re: java.lang.RuntimeException: mapped-name is required for
            bai yong Newbie

            java.lang.RuntimeException: mapped-name is required for jdbc/GADB of deployment StockinBusinessEJB
            at org.jboss.injection.ResourceHandler.loadXmlResourceRefs(ResourceHandler.java:94)
            at org.jboss.injection.ResourceHandler.loadXml(ResourceHandler.java:167)
            at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:356)
            at org.jboss.ejb3.SessionContainer.processMetadata(SessionContainer.java:140)
            at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:292)
            at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:356)
            at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
            at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)