1 Reply Latest reply on Oct 11, 2004 4:37 AM by robisz

    Problem with CMP and DefaultDS and EJB Deploy

    juan110470

      I have the following in my mysql-ds.xml file:

      <?xml version="1.0" encoding="UTF-8"?>

      <!-- $Id: mysql-ds.xml,v 1.1.2.1 2003/12/12 19:19:56 starksm Exp $ -->
      <!-- Datasource config for MySQL using 3.0.9 available from:
      http://www.mysql.com/downloads/api-jdbc-stable.html
      -->


      <local-tx-datasource>
      <jndi-name>somedatasource</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/dbname</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      passwd
      </local-tx-datasource>

      <local-tx-datasource>
      <jndi-name>ejbpool</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/ejb</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      passwd
      </local-tx-datasource>



      I am trying to deploy some entity beans (CMP) and the container won't deploy my beans because it can't find the DefaultDS.

      I am telling the container to use one of the datasources above in the following files:

      ejb-jar.xml (abbreviated)

      <ejb-name>ProductEJB</ejb-name>
      examples.ProductHome
      examples.Product
      <ejb-class>examples.ProductBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>

      False

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

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ProductBean</abstract-schema-name>

      <cmp-field>
      <field-name>productID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>basePrice</field-name>
      </cmp-field>

      <primkey-field>productID</primkey-field>


      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE name = ?1]]>
      </ejb-ql>



      <query-method>
      <method-name>findByDescription</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE description = ?1]]>
      </ejb-ql>



      <query-method>
      <method-name>findByBasePrice</method-name>
      <method-params>
      <method-param>double</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE basePrice = ?1]]>
      </ejb-ql>



      <query-method>
      <method-name>findExpensiveProducts</method-name>
      <method-params>
      <method-param>double</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE basePrice > ?1]]>
      </ejb-ql>



      <query-method>
      <method-name>findCheapProducts</method-name>
      <method-params>
      <method-param>double</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE basePrice < ?1]]>
      </ejb-ql>



      <query-method>
      <method-name>findAllProducts</method-name>
      <method-params>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE productID IS NOT NULL]]>
      </ejb-ql>



      jboss.xml (abbreviated)


      <ejb-name>ProductEJB</ejb-name>
      <jndi-name>Product</jndi-name>
      <resource-ref>
      <res-ref-name>jdbc/ejbpool</res-ref-name>
      <jndi-name>ejbpool</jndi-name>
      </resource-ref>


      The error happens always when I try to deploy these beans. Why is JBOSS looking for a DefaultDS when I want these beans to use the datasources I have defined above.

      This is driving me nuts.

      Thanks

        • 1. Re: Problem with CMP and DefaultDS and EJB Deploy
          robisz

          Don't use resource-ref element for configuring datasource for a
          CMP bean. You can configure it through jbosscmp-jdbc.xml file.

          The default configuration is in JBOSS_HOME/server/YOUR_CONF/conf/standardjbosscmp-jdbc.xml file

          You should set the CMP datasource here:

          <jbosscmp-jdbc>
          
           <defaults>
           <datasource>java:/ejbpool</datasource>
           <datasource-mapping>mySQL</datasource-mapping>
           ...