4 Replies Latest reply on Nov 26, 2007 3:58 AM by Heiko Dähn

    Problem with resource-mapping

    Heiko Dähn Newbie


      this is in my SessionBean:

      @Resource(name="myDB", mappedName="java:/MyDefaultDS")
      DataSource dataSource;

      I deploy this in an ear-File, that looks like this:
      - myBean.ear
       - META-INF

      In my server/default/deploy-Folder is an oracle-ds.xml-File with following Content:


      Now, I have an application that shall uses the 'TheOtherDS'. I can use a DeploymentDescriptor for each Bean but I would like to say it in one File for all:
      "Please use for the resource "myDB" the global Name "java:/TheOtherDS".
      Is this possible?

        • 1. Re: Problem with resource-mapping
          wayne baylor Apprentice

          do you mean you want to use the same deployment descriptor for each bean, or that you want the beans to have the same code and just change the descriptor?

          • 2. Re: Problem with resource-mapping
            Heiko Dähn Newbie

            I mean that the Resource-name('myDB') is mapped on a datasource ear-wide. First I thought you can make this in a jboss-app.xml or applikation.xml like you can do that in a jboss-web.xml but that doesnt work.

            My problem is, I would like to avoid to build a deployment descriptor for twenty or more beans in an applikation. With my beans I want to make up reusable code. So I decided, that every datasource gets the name 'myDB' and is mapped to the global jndi-name 'java:/MyDefaultDS'. Now I have the problem that more than one applikation is deployed on a server with different databases. I can manage this with a deployment descriptor in each bean but that is to complicated.

            I hope the problem is more perspicuous even if my english is a disaster.

            • 3. Re: Problem with resource-mapping
              wayne baylor Apprentice

              i would make each bean that needs a datasourse use a local jndi lookup instead of a global one. since you only have one jar you will only need one ejb-jar.xml and one jboss.xml.

              doing it this way you can keep your bean code the same, for example all lookups could be:

              DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/MyDS");

              then in the jboss.xml you can map the lookup to the proper data source on a per bean basis.

              • 4. Re: Problem with resource-mapping
                Heiko Dähn Newbie

                How does look the mapping in a jboss.xml and ejb-jar.xml?