1 Reply Latest reply on Nov 2, 2004 9:40 PM by Russ Loucks

    Using Mysql as DataSource

    Pedro Martins Newbie

      Hi, I am trying to deploy an EJB and want to use Mysql. How should i complete the following fields:

      File xdoclet.xml:

      <jboss
       version="3.0"
       unauthenticatedPrincipal="nobody"
       xmlencoding="UTF-8"
       destdir="${ejb.dd.dir}"
       validatexml="false"
       datasource="REPLACE_HERE"
       datasourcemapping="REPLACE_HERE"
       preferredrelationmapping="foreign-key"
      />
      


      File StoreAccessBean.java

      @ejb.resource-ref res-ref-name="REPLACE_HERE"
       res-type="javax.sql.Datasource"
       res-auth="Container"
      
      @jboss.resource-ref res-ref-name="REPLACE_HERE"
       jndi-name="REPLACE_HERE"


      Thank you very much,
      Pedro Martins

        • 1. Re: Using Mysql as DataSource
          Russ Loucks Newbie

          Here's my build.xml file for 'xdoclet' task to generate JBoss descriptor file:

          <jboss
           version="3.2"
           datasource="java:/storeDS"
           datasourcemapping="mySQL"
           destdir="dd/ejb"
          >
          


          In an (entity) bean:

           * @ejb.bean
           * name="Customer"
           * type="CMP"
           * view-type="local"
           * primkey-field="customerKey"
           * @ejb.persistence
           * table-name="store_customer"
           * @jboss.persistence
           * create-table="no"
           * remove-table="no"
           * @jboss.unknown-pk
           * class="java.lang.Integer"
           * column-name="customerKey"
           * jdbc-type="INTEGER"
           * sql-type="INTEGER"
           * auto-increment="true"
           * @jboss.entity-command
           * name="mysql-get-generated-keys"
           * class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand"
          


          Then, in $JBOSS_HOME/server/default/deploy/mysql-ds.xml:

          <datasources>
           <local-tx-datasource>
           <jndi-name>storeDS</jndi-name>
           <connection-url>jdbc:mysql://hostname:3306/storeDS</connection-url>
           <driver-class>com.mysql.jdbc.Driver</driver-class>
           <user-name>username</user-name>
           <password>password</password>
           </local-tx-datasource>
          </datasources>
          


          Hope this helps. Note I'm using 'auto_increment' for my primary key fields.