1 Reply Latest reply on Oct 7, 2002 2:14 PM by aloubyansky

    JBoss3.0 -> CMP and datasource

    mik1

      Hello everyone,

      I currently use JBoss3.0 with MySQL and I have a problem with regard to the requests which I can make on my EJBs in mode CMP.

      According to what I understood, one can make only requests of the type SELECT but I will like to be able to make UPDATE and DELETE.

      I thus tried to use a DataSource object with the following method :
      private DataSource getDataSource() {
      try {
      Context ctx = new InitialContext();
      String dataSourceName = (String) ctx.lookup("java:comp/env/DataSourceName");
      return (DataSource) ctx.lookup(dataSourceName);
      } catch(NamingException ne) {
      throw new EJBException("Naming lookup failure : "+ne.getMessage());
      }
      }

      But I can't manage to bound my database like this, why ?
      I've heard about env-entry... but how can I use it ?

        • 1. Re: JBoss3.0 -> CMP and datasource
          aloubyansky

          To lookup a datasource in java:/comp/env, it should be bound there first. This is done the following way.
          in ejb-jar.xml:

          <ejb-name>MyEJB</ejb-name>
          ...
          <resource-ref>
          <!-- this is a logical name -->
          <res-ref-name>jndi/ApplicationDS</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          </resource-ref>
          ...


          in jboss.xml:

          <ejb-name>MyEJB</ejb-name>
          ...
          <resource-ref>
          <res-ref-name>jndi/ApplicationDS</res-ref-name>
          <!-- this is actual JNDI name -->
          <jndi-name>java:/KNInnerDS</jndi-name>
          </resource-ref>


          Then in some MyEJB's method:
          InitialContext ic = new InitialContext();
          DataSource ds = (DataSource)ic.lookup( "java:/comp/env/jndi/ApplicationDS" );

          But if SELECT, UPDATE and DELETE are done this way, then why use CMP?