8 Replies Latest reply on Sep 3, 2003 4:15 AM by fredatwork

    MySQL CMP and auto-increment

    alpine

      I have read every message on this board about autoincrement and haven't found any resolution.


      Note that I have already switched the 3.0 to the 3.2 as one person claimed was a solution.

      Also, I still get this error:
      10:50:54,015 ERROR [XmlFileLoader] XmlFileLoader: File jar:file:/E:/project_apps/jboss-3.2.1_tomcat-4.1.24/ser
      ver/default/tmp/deploy/server/default/deploy/go_links.jar/39.go_links.jar!/META-INF/jbosscmp-jdbc.xml process
      error. Line: 25. Error message: Element type "auto-increment" must be declared.
      10:50:54,031 ERROR [XmlFileLoader] XmlFileLoader: File jar:file:/E:/project_apps/jboss-3.2.1_tomcat-4.1.24/ser
      ver/default/tmp/deploy/server/default/deploy/go_links.jar/39.go_links.jar!/META-INF/jbosscmp-jdbc.xml process
      error. Line: 26. Error message: The content of element type "cmp-field" must match "(field-name,read-only?,rea
      d-time-out?,column-name?,not-null?,((jdbc-type,sql-type)|property+)?)".

      Any ideas?


      Here is my jbosscmp-jdbc.xml file:

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

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

      <jbosscmp-jdbc>


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


      <enterprise-beans>

      <ejb-name>LinkEJB</ejb-name>
      <table-name>link</table-name>
      <cmp-field>
      <field-name>ID</field-name>
      <column-name>ID</column-name>
      <auto-increment/>
      </cmp-field>
      <cmp-field>
      <field-name>URL</field-name>
      <column-name>URL</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>Description</field-name>
      <column-name>DESCRIPTION</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>Category</field-name>
      <column-name>CATEGORY</column-name>
      </cmp-field>
      <entity-command name="mysql-get-generated-keys"/>

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

      Thanks for any help on this matter.

        • 1. Re: MySQL CMP and auto-increment
          viz

          auto_increment does work as I have it working on two tables and with CMR!

          Your jbosscmp-jdbc.xml looks fine.

          I can give you a working setup?

          Kind regards,
          --
          Marc

          • 2. Re: MySQL CMP and auto-increment
            alpine

            Viz,

            Yes, please do. Thanks!

            • 3. Re: MySQL CMP and auto-increment
              alpine

              I discovered these examples which have helped greatly:

              http://www.oreilly.com/catalog/entjbeans3/workbooks/

              and managed to get the autoincrement to work. I do have one question: I am unable to get the auto generated primary key. I noticed that you need to put a getGeneratedPrimaryKey method into the code, but no matter what I do I seem to get a null pointer message.

              Does anyone know where to insert the getGeneratedPrimaryKey() method in order to get it to work? I put references to it into my Bean and Remote classes but I always get a null pointer exception. Thanks.

              • 4. Re: MySQL CMP and auto-increment
                viz

                 

                "Viz" wrote:
                Here is a setup that works for me.


                • 5. Re: MySQL CMP and auto-increment
                  viz

                  You do not need to do anything in the code if you use a similar setup to the one I have posted.

                  I struggled to get this to work and there is a lot of confusing info out there. I have been meaning to put a little document together to spell it out simply, but time has evaded me :-)

                  Kind regards,
                  --
                  Marc

                  • 6. Re: MySQL CMP and auto-increment
                    viz

                    Also, if you need the java file I can let you have these also - I didn't include them as I did not want to appear as if I was teaching my Grandmother to suck eggs :-)

                    Kind regards,
                    --
                    Marc

                    • 7. Re: MySQL CMP and auto-increment
                      xavierpayne2

                      if you are still watching this thread... please do post your .java.

                      I have the descriptors looking good but still don't know what the create and postcreate for my bean is supposed to look like. I tried them args and I just get null pointer exceptions.

                      • 8. Re: MySQL CMP and auto-increment
                        fredatwork

                        Hello,

                        Could you please let me know how did you solve the problem. I have exactly the same one and the <auto-increment/> tag is not accepted.

                        I checked the EJB samples you mention, but I dod not find any reference to <auto-increment/>.

                        Thanks in advance for you tip.

                        PS: I run JBoss 3.2 and MySQL 3.23.