3 Replies Latest reply on May 18, 2002 12:02 AM by davidjencks

    Sharing a Datasource

      I've got a call that goes to a Stateless Session Bean. In that bean I get a Datasource from a JNDI reference. I've also declared the reference in ejb-jar.xml and jboss.xml.

      == ejb-jar ==

      ....
      <resource-ref>

      <res-ref-name>jdbc/MyDatabase</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      ==

      == jboss.xml ==
      <resource-managers>
      <resource-manager>
      <res-name>jdbc/MyDatabase</res-name>
      <res-jndi-name>java:/MyDatabaseDS</res-jndi-name>
      </resource-manager>
      </resource-managers>
      ===

      Everything works fine until I call another Stateless Session bean from the initial bean that uses the same datasource.

      It seems to work fine if I don't get a datasource prior to the call to the other session bean but, the following fails.

      // get datasource in outer session bean
      // get local home to other session
      // get local interface to other session
      // get datasource
      // use datasource
      // return results to outer bean
      // use results and make a database call.

      If I wait to get the datasource until after I've made the call to the inner bean, it works.

      How can I share this datasource within the same context?
      When a connection is created from a datasource in this fashion, is it necessary to close the connection or is that handled by the container?

      Thanks for any input.

        • 1. Re: Sharing a Datasource
          davidjencks

          ALWAYS TELL US WHAT JBOSS VERSION YOU ARE USING!

          Always close all your connections when you are done with them. Pre 3.0 rc1, this means in a finally block in the same method you got the connection. In 3.0 rc1 and later, you can hold connections over method boundaries, but you are still responsible for closing them when you are done.

          • 2. Re: Sharing a Datasource

            I apologize. It's 3.0RC1. I am closing them and the problem stated above still exists.

            • 3. Re: Sharing a Datasource
              davidjencks

              What exactly is the failure? Can you show the actual code and stack trace? Are you getting a connection before the call to the inner session bean? If so rc1 will object with an "associate connection not supported" type message, and you should upgrade to rc2 and the new Local jdbc wrapper.