5 Replies Latest reply on Dec 8, 2004 7:40 AM by chatbuilder

    CMP with mySql

    chatbuilder

      Hi,

      I still have problems let my CMP bean, interact with mySQL. My bean still saves the data into the HyperSonic DB. My mysql-ds.xml is configured right, because when startup jboss4.0, there are two tables (jms_messages, jms_transactions) automat created into my mySql db.

      I also added the mysql-jdbc2-service.xml file into the deploy\jms directory and removed the hsqldb-jdbc2-service.xml from the deploy\jms directory.

      Below my three xml files, that I save in the META-INF of my bean jar.

      1) jbosscmp-jdbc.xml
      ------------------------------------------------------------------------------- -----------------
      <?xml version="1.0" encoding="UTF-8"?>

      <jbosscmp-jdbc>



      java:/MySqlDS
      <datasource-mapping>mySQL</datasource-mapping>


      <enterprise-beans>

      <ejb-name>Initiaal</ejb-name>
      <table-name>initialen</table-name>
      <cmp-field>
      <field-name>initiaal</field-name>
      <column-name>initiaal</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>naam</field-name>
      <column-name>naam</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>dienst</field-name>
      <column-name>dienst</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>email</field-name>
      <column-name>email</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>telefoon</field-name>
      <column-name>telefoon</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lockindicator</field-name>
      <column-name>lockindicator</column-name>
      </cmp-field>

      </enterprise-beans>
      </jbosscmp-jdbc>

      2) jboss.xml
      ------------------------------------------------------------------------------- -----------------
      <?xml version="1.0"?>


      <enterprise-beans>

      <ejb-name>Initiaal</ejb-name>
      <jndi-name>InitialenBean</jndi-name>

      </enterprise-beans>


      3) ejb-jar.xml
      ------------------------------------------------------------------------------- -----------------
      <?xml version="1.0"?>

      <ejb-jar
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
      http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
      version="2.1">

      <display-name>Initialen</display-name>

      <enterprise-beans>

      Encapsulates a User
      <ejb-name>Initiaal</ejb-name>
      hotline.beheerhotline.basisbestanden.initialen.InitialenHomeRemote
      hotline.beheerhotline.basisbestanden.initialen.InitialenRemote< /remote>
      <ejb-class>hotline.beheerhotline.basisbestanden.initialen.InitialenBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <cmp-version>2.x</cmp-version>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False

      <abstract-schema-name>initialen</abstract-schema-name>
      <cmp-field><field-name>initiaal</field-name></cmp-field>
      <cmp-field><field-name>naam</field-name></cmp-field>
      <cmp-field><field-name>dienst</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>
      <cmp-field><field-name>telefoon</field-name></cmp-field>
      <cmp-field><field-name>id</field-name></cmp-field>
      <cmp-field><field-name>lockindicator</field-name></cmp-field>
      <primkey-field>id</primkey-field>


      </enterprise-beans>

      <assembly-descriptor>
      <container-transaction>

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

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


      </ejb-jar>

      Last my mysql-ds.xml
      -------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>


      <local-tx-datasource>
      <jndi-name>MySqlDS</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/hotline</connection-url> ;
      <driver-class>org.gjt.mm.mysql.Driver</driver-class>
      <user-name>root</user-name>

      </local-tx-datasource>


      It would be grate if somebody knows where I'm wrong.

      Thx in adv,
      Pieter

        • 1. Re: CMP with mySql
          darranl

          Are you sure that both of the deployment descriptors are in the META-INF of your jar?

          Also the -ds.xml goes in the deploy folder of your selected JBoss configuration not in the META-INF of the component.

          • 2. Re: CMP with mySql
            chatbuilder

            Yes yes, I'm sure

            my jar consists of:

            + hotline
            |-+ beheerhotline
            |--+ basisbestanden
            |---+ initialen
            |----- InitialenHomeRemote
            |----- InitialenRemote
            |----- InitialenBean
            + META-INF
            |- ejb-jar.xml
            |- jboss.xml
            |- jbosscmp-jdbc.xml

            I putted the jar in my deploy dir together with the mysql-ds.xml

            Pieter

            • 3. Re: CMP with mySql
              raist_majere

              Did you remove the hsqldb-ds.xml file from the deploy dir and copied the MySQL JDBC drivers into the server/{yourconfig}/lib dir?

              • 4. Re: CMP with mySql
                darranl

                The hsqldb-ds.xml shouldn't need to be removed from the deploy directory, it is possible to run with both in parallel.

                Also as the two JMS tables are being created the driver must have been found so that the connection can be established.

                Unless JBoss is ignoring the jbosscmp-jdbc.xml file it looks to me as if there may be a slight packaging error that is causing the file to be missed.

                • 5. Re: CMP with mySql
                  chatbuilder

                  darranl, you're right my jboss ignores my jbosscmp-jdbc.xml file. I know because when I add wrong XML syntacs, my jboss doesn't complain.

                  darranl is't it possible to send me a working CMP bean that uses MySql, it would help me a lot. Then I can be sure I'm using the right structure.

                  email is Pieter at ChatBuilder.com

                  Thx in adv.
                  Pieter