7 Replies Latest reply on Sep 9, 2004 6:21 PM by darranl

    CMP, JBoss & MySql problems

    buzzfield

      Hi there, I'm an EJB newbe striving with a problem. I'm trying to get a very simple CMP example taken from the book "Enterprise Java Beans" to work with JBoss 3.2.5 and MySql v.4.0.15 (with driver v. 3.0.11). So, Jboss sees my connection pretty well, since I made a few BMP Entity beans work flawlessly. However, when I try to deploy a CMP Bean, I keep getting an error: org.jboss.deployment.DeploymentException: Error in jbosscmp-jdbc.xml : datasource-mapping MySqlDS not found. I've tried out several solutions found on forums. Some of them allegedly worked, but not for me!!! Please, HELP!!!!!!!! I post my files below (at least the last attempt I made).

      Thanks a lot!

      _________________
      mysql-ds.xml
      _________________

      <?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>MySqlDS</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/EJBDatabase</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>

      </local-tx-datasource>




      _________________
      ejb-jar.xml
      _________________

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC
      "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
      "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      CMP Customer Entity Bean
      <display-name>Ship DB Application</display-name>
      <enterprise-beans>


      <!-- CMP Entity definition -->
      <ejb-name>CustomerCMP</ejb-name>
      CustomerCMP.CustomerHome
      CustomerCMP.CustomerRemote
      <ejb-class>CustomerCMP.CustomerBean</ejb-class>
      <prim-key-class>java.lang.Integer</prim-key-class>
      <persistence-type>Container</persistence-type>
      false
      <cmp-version>2.x</cmp-version>

      <!-- Abstract schema for the CMP Bean -->
      <abstract-schema-name>Customer</abstract-schema-name>
      <cmp-field><field-name>id</field-name></cmp-field>
      <cmp-field><field-name>lastName</field-name></cmp-field>
      <cmp-field><field-name>firstName</field-name></cmp-field>
      <cmp-field><field-name>hasGoodCredit</field-name></cmp-field>
      <primkey-field>id</primkey-field>
      <security-identity><use-caller-identity/></security-identity>

      <!-- Define datasource to be used -->
      <resource-ref>
      <res-ref-name>jdbc/EJBDatabase</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      </enterprise-beans>

      <!-- Assembly descriptor -->
      <assembly-descriptor>

      <security-role>
      <role-name>Employees</role-name>
      </security-role>

      <method-permission>
      <role-name>Employees</role-name>

      <ejb-name>CustomerCMP</ejb-name>
      <method-name>*</method-name>

      </method-permission>
      <container-transaction>

      <ejb-name>CustomerCMP</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>

      </ejb-jar>

      _________________
      jbosscmp-jdbc.xml
      _________________

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

      <!DOCTYPE jbosscmp-jdbc PUBLIC
      "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
      "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

      <jbosscmp-jdbc>


      jdbc/EJBDatabase
      <datasource-mapping>MySqlDS</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>true</remove-table>



      <enterprise-beans>

      <ejb-name>CustomerCMP</ejb-name>
      <table-name>Customer</table-name>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastName</field-name>
      <column-name>LAST_NAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>firstName</field-name>
      <column-name>FIRST_NAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>hasGoodCredit</field-name>
      <column-name>HAS_GOOD_CREDIT</column-name>
      </cmp-field>

      </enterprise-beans>

      </jbosscmp-jdbc>


      _________________
      jboss.xml
      _________________
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN"

      "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">



      <enterprise-beans>

      <ejb-name>CustomerCMP</ejb-name>
      <jndi-name>CustomerCMP</jndi-name> <!-- Chang Jndi name if you want

      to use something else -->


      <reference-descriptor>
      <!-- Resource description for MySql datasource -->
      <!-- Here we bind the actual DS to its jndi name -->
      <!-- Specs must match those found in ejb-jar.xml <resource-ref>

      descriptor -->
      <!-- & descriptors found in jbosscmp-jdbc.xml and

      jaws.xml -->
      <resource-description>
      <res-ref-name>jdbc/EJBDatabase</res-ref-name>
      <jndi-name>java:/MySqlDS</jndi-name>
      </resource-description>
      </reference-descriptor>

      </enterprise-beans>

        • 1. Re: CMP, JBoss & MySql problems
          darranl

          Try

          <datasource-mapping>mySQL</datasource-mapping>


          • 2. Re: CMP, JBoss & MySql problems
            buzzfield

            Thanks, but it didn't work. Now the error msg is: "datasource-mapping MySql not found"... I'm really puzzled... Any other proposal?

            • 3. Re: CMP, JBoss & MySql problems
              darranl

              Can you please use cut and paste instead of typing by hand.

              Did you change the case to MySql when you copied the example to your deployment descriptor or did you change the case of the error message?

              • 4. Re: CMP, JBoss & MySql problems
                buzzfield

                Apologies for my lack of accuracy. I made the change you recommended to jbosscmp-jdb.xml. Here is the screen dump of the error messages, and the current deployment descriptors.

                Thanks again :-)

                _______________________
                ERROR MESSAGES
                _______________________

                MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM:
                ObjectName: jboss.j2ee:jndiName=CustomerCMP,service=EJB
                state: FAILED
                I Depend On:
                Depends On Me: MBeanException: org.jboss.deployment.DeploymentException:

                Error
                in jbosscmp-jdbc.xml : datasource-mapping MySql not found
                Cause: org.jboss.deployment.DeploymentException: Error in jbosscmp-jdbc.xml

                : da
                tasource-mapping MySql not found
                ObjectName: jboss.j2ee:jndiName=CustomerCMP,plugin=pool,service=EJB
                state: CREATED
                I Depend On:
                Depends On Me:

                16:17:27,776 INFO [EJBDeployer] Undeploying:

                file:/D:/Development/jboss-3.2.5/s
                erver/default/deploy/CustomerCMP.jar
                16:17:27,786 INFO [EjbModule] Undeployed: CustomerCMP
                16:17:27,786 WARN [DeploymentInfo] Could not delete

                file:/D:/Development/jboss-
                3.2.5/server/default/tmp/deploy/tmp28322CustomerCMP.jar restart will delete it

                _______________________
                ejb-jar.xml
                _______________________

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE ejb-jar PUBLIC
                "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
                "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
                <ejb-jar>
                CMP Customer Entity Bean
                <display-name>Ship DB Application</display-name>
                <enterprise-beans>


                <!-- CMP Entity definition -->
                <ejb-name>CustomerCMP</ejb-name>
                CustomerCMP.CustomerHome
                CustomerCMP.CustomerRemote
                <ejb-class>CustomerCMP.CustomerBean</ejb-class>
                <prim-key-class>java.lang.Integer</prim-key-class>
                <persistence-type>Container</persistence-type>
                false
                <cmp-version>2.x</cmp-version>

                <!-- Abstract schema for the CMP Bean -->
                <abstract-schema-name>Customer</abstract-schema-name>
                <cmp-field><field-name>id</field-name></cmp-field>
                <cmp-field><field-name>lastName</field-name></cmp-field>
                <cmp-field><field-name>firstName</field-name></cmp-field>
                <cmp-field><field-name>hasGoodCredit</field-name></cmp-field>
                <primkey-field>id</primkey-field>
                <security-identity><use-caller-identity/></security-identity>

                <!-- Define datasource to be used -->
                <resource-ref>
                <res-ref-name>jdbc/EJBDatabase</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                </resource-ref>


                </enterprise-beans>

                <!-- Assembly descriptor -->
                <assembly-descriptor>

                <security-role>
                <role-name>Employees</role-name>
                </security-role>

                <method-permission>
                <role-name>Employees</role-name>

                <ejb-name>CustomerCMP</ejb-name>
                <method-name>*</method-name>

                </method-permission>
                <container-transaction>

                <ejb-name>CustomerCMP</ejb-name>
                <method-name>*</method-name>

                <trans-attribute>Required</trans-attribute>
                </container-transaction>
                </assembly-descriptor>

                </ejb-jar>

                _______________________
                jbosscmp-jdbc.xml
                _______________________

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

                <!DOCTYPE jbosscmp-jdbc PUBLIC
                "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
                "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

                <jbosscmp-jdbc>


                jdbc/EJBDatabase
                <datasource-mapping>MySql</datasource-mapping>
                <create-table>true</create-table>
                <remove-table>true</remove-table>



                <enterprise-beans>

                <ejb-name>CustomerCMP</ejb-name>
                <table-name>Customer</table-name>
                <cmp-field>
                <field-name>id</field-name>
                <column-name>ID</column-name>
                </cmp-field>
                <cmp-field>
                <field-name>lastName</field-name>
                <column-name>LAST_NAME</column-name>
                </cmp-field>
                <cmp-field>
                <field-name>firstName</field-name>
                <column-name>FIRST_NAME</column-name>
                </cmp-field>
                <cmp-field>
                <field-name>hasGoodCredit</field-name>
                <column-name>HAS_GOOD_CREDIT</column-name>
                </cmp-field>

                </enterprise-beans>

                </jbosscmp-jdbc>


                _______________________
                jboss.xml
                _______________________

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">



                <enterprise-beans>

                <ejb-name>CustomerCMP</ejb-name>
                <jndi-name>CustomerCMP</jndi-name> <!-- Chang Jndi name if you want to use something else -->


                <reference-descriptor>
                <!-- Resource description for MySql datasource -->
                <!-- Here we bind the actual DS to its jndi name -->
                <!-- Specs must match those found in ejb-jar.xml <resource-ref> descriptor -->
                <!-- & descriptors found in jbosscmp-jdbc.xml and jaws.xml -->
                <resource-description>
                <res-ref-name>jdbc/EJBDatabase</res-ref-name>
                <jndi-name>java:/MySqlDS</jndi-name>
                </resource-description>
                </reference-descriptor>

                </enterprise-beans>

                • 5. Re: CMP, JBoss & MySql problems
                  darranl

                  Try mySQL not MySQL

                  • 6. Re: CMP, JBoss & MySql problems
                    buzzfield

                    THANKS! :-)

                    It worked, with a little of extra "stuff"... So, I post the complete solution, plus a couple of questions (note: I'll just post the parts of the files that changed...)

                    ______________________
                    jbosscmp.jdbc
                    ______________________

                    *** CHANGED:


                    java:/MySqlDS <!-- WAS: jdbc/EJBDatabase -->
                    <datasource-mapping>mySQL</datasource-mapping> <!-- WAS: MySql -->
                    <create-table>true</create-table>
                    <remove-table>true</remove-table>


                    *** QUESTION:
                    *** Why did I have to change 'MySql' to 'mySQL'? Is it because the file
                    *** standardjbosscmp-jdbc.xml has a reference to 'mySQL', and not
                    *** 'MySql'?

                    ______________________
                    jbosscmp-jdbc.xml
                    ______________________

                    *** CHANGED:


                    java:/MySqlDS
                    <datasource-mapping>mySQL</datasource-mapping>
                    <create-table>true</create-table>
                    <remove-table>true</remove-table>


                    *** EXPLAINATION: I just noticed the datasource name assigned to
                    *** the SQL source by JBoss during its startup (i.e. 'java:/MySqlDS')
                    *** and I used 'mySQL' mapping name for coeherency with
                    *** jbosscmp-jdbc.xml

                    ______________________
                    ejb-jar.jdbc
                    ______________________

                    *** CHANGED: I eliminated

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

                    *** EXPLAINATION: just a hunch... I mean, since the datasource was
                    *** defined by JBoss at startup time, I figured that it would be
                    *** unnecessary to redefine it.

                    ***QUESTION: Why was I right? When is it actually necessary to use
                    *** <resource-ref> tags to define datasources, and what's the right way
                    *** of doing it?

                    Finally, I feel I need to learn much more. Any tutorial/book as to what-goes-where-and-why that you could recommend?

                    A HUGE thanks for your help! You really got me out of a big deal of frustration!!! :-)

                    • 7. Re: CMP, JBoss & MySql problems
                      darranl

                      Yes the problem was just down to the case of the mapping.

                      It looks like you are using the book I would reccomend anyway to get an understanding of J2EE, as you have noticed it doesn't cover application server specifics (Like how to use a different database server).

                      Have you had a look at the JBoss Getting Started Guide? It has examples of deploying different types of components on JBoss and I think it is very useful if you have already gained an understanding of the theory of J2EE.