1 2 3 Previous Next 31 Replies Latest reply on Feb 11, 2004 3:05 PM by mingdong Go to original post
      • 15. Re: delay-database-insert-until and autogenerated PKs
        dklehmann

        Sebastien,

        Thanks for your suggestions.

        I am now using xdoclet 1.2b2 and it seems that my jbosscmp-jdbc.xml is generated correctly. I also realized that my Microsoft JDBC driver only implemented version 2.0 and so I downloaded the JSQLConnect driver which seems to be working ok.

        Unfortunately, I am still not quite there as I keep getting a deployment error due to (at least so it seems) a wrong entity command. I either receive a 'template not found' or a 'String index out of range: 0' depending on which entity-command I try.

        I tried: 'pk-sql', 'JDBCGetGeneratedKeysCreateCommand', and a few other values, but none work so far. I haven't really found a good answer which command to use anywhere else either...

        Can anyone help?

        Daniel

        • 16. Re: delay-database-insert-until and autogenerated PKs
          dklehmann

          So, I just figured out the problem, I think. It seems that JBoss3.2.0RC3 as well as JBoss3.2.0 both do not include the JDBCGetGeneratedKeysCreateCommand.class. At least I could not find it anywhere. I tried to add the class from a source download to jboss.jar (where I think it should go), but JBoss still cannot load the class (at least that's the error I am getting).

          It seems odd that this class is not included. Does anyone have any insight on this? Or does anyone know which jar it should be added to?

          Thanks for the help.

          Daniel

          • 17. Re: delay-database-insert-until and autogenerated PKs
            sebastien_petrucci

            Hi all,

            JBoss 3.2.1 is now available.

            The release notes indicates that a create command for MS SQL SERVER has been added. You should check it out. (JDBCMsSQLCreateCommand.java)

            Regards,

            Sebastien.

            • 18. Re: delay-database-insert-until and autogenerated PKs
              dklehmann

              Phew,

              So, finally figured out how to get auto-increment to work with MS SQL 2000 and jboss 3.2.1.

              If anyone is interested in any details, let me know.

              Thanks to Sebastien for his pointers.

              Daniel

              • 19. Re: delay-database-insert-until and autogenerated PKs
                sebastien_petrucci

                Hurra !!

                ;-)

                • 20. Re: delay-database-insert-until and autogenerated PKs
                  comptedeouf

                  Daniel,
                  I am very interested in the details, please post your
                  findings.
                  Thanks,

                  • 21. Re: delay-database-insert-until and autogenerated PKs
                    dklehmann

                    Alright, here we go.

                    The example assumes you are using jboss 3.2.1, ant 1.5.1, and xdoclet 1.2b2 on Windows 2000. The database is MS SQL 2000 and JDBC driver is Microsoft's JDBC Driver for MS SQL (can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&DisplayLang=en)



                    Steps:



                    1. Environment

                    a. JBoss 3.2.x or higher. Earlier versions of JBoss only support auto-incremenent for certain databases (e.g. MySQL, but not MS SQL 2000)

                    b. Xdoclet 1.2b2 or higher. Older Xdoclet-versions do not support auto-increment.

                    c. The database-connection must be configured before



                    2. Check standardjbosscmp.jdbc.xml

                    a. Check if an entity-command exists for the database-product you are using. This is not the case for MS SQL 2000 (included the example anyway, fyi). Example (for MySQL):

                    <!-- this command requires auto-increment element for unknown-pk -->
                    <entity-command name="mysql-get-generated-keys"
                    class="org.jboss.ejb.plugins.cmp.jdbc.mysql.JDBCMySQLCreateCommand"/>


                    b. The following entry needs to be checked in standardjbosscmp-jdbc.xml. There has to be an &#8216;auto-increment-template&#8217; tag for the database you are using (The tag exists for MySQL, but not MS SQL 2000). Should there not be a tag, it has to be created. Also, a value has to be assigned, although it seems that it does not matter what this value is (here for example &#8216;this_is_just_a_token&#8217;):

                    <type-mapping>
                    MS SQLSERVER2000
                    <row-locking-template>SELECT ?1 FROM ?2 with (rowlock) WHERE ?3</row-locking-template>
                    <pk-constraint-template>CONSTRAINT ?1 PRIMARY KEY (?2)</pk-constraint-template>
                    <fk-constraint-template>ALTER TABLE ?1 ADD CONSTRAINT ?2 FOREIGN KEY (?3)
                    REFERENCES ?4 (?5)</fk-constraint-template>
                    <auto-increment-template>this_is_just_a_token</auto-increment-template>


                    c. If JDK 1.4 and a JDBC 3.0 driver are being used, it is also possible to use the generic &#8216;get-generated-keys&#8217; entity-command. The configuration is the same as with the other examples (that need a JDBC 2.0 driver as a prerequisite). Only it has to be ensured that the following entry is not commented out in standardjbosscmp-jdbc.xml (which is sometimes the case):

                    <entity-command name="get-generated-keys"
                    class="org.jboss.ejb.plugins.cmp.jdbc.jdbc3.JDBCGetGeneratedKeysCreateCommand"/>




                    3. Write the xdoclet tags in the bean implementation

                    a. The &#8218;jboss.entity-command-name&#8217; class-level tag has to be added to the bean-implementation.

                    i. If standardjbosscmp-jdbc.xml has an entry for the used database (as is the case for MySQL) the tag looks as follows:

                    * @jboss.entity-command name="mysql-get-generated-keys"
                    **/
                    public abstract class OrderEntityBean implements EntityBean


                    ii. If there is no &#8218;entity-command&#8217; entry in standarjbosscmp-jdbc.xml for the used database (as is the case for MS SQL 2000 in JBoss 3.2.1) the entry looks as follows (the class implementation has to exist on JBoss - ok on JBoss 3.2.1 for MSSQL - or it has to be written - the entity-command-name can be chosen freely).

                    * @jboss.entity-command name="get-mssql-generated-keys"
                    *class="org.jboss.ejb.plugins.cmp.jdbc.mssql.JDBCMsSQLCreateCommand"
                    **/
                    public abstract class OrderEntityBean implements EntityBean


                    b. On the method-level the auto-increment tag has to be added (fort he primary-key field):

                    /*******************************************
                    * Retrieve the id
                    *
                    * @return Returns an int representing the order id
                    *
                    * @ejb.persistence
                    * @ejb.pk-field
                    *
                    * @jboss.column-name name="OrderId"
                    * @jboss.persistence auto-increment="true"
                    **/
                    public abstract int getOrderId();

                    /**
                    * Set the order's id
                    *
                    * @param pOrderId The id of this OrderEntity. Is set at creation time.
                    **/
                    public abstract void setOrderId( int pOrderId );




                    4. build.xml:

                    a. In the &#8216;ejbdoclet&#8217; task all jars in [XDocletInstallationDirectory]\lib have to be listed in the fileset.

                    b. The etnry in the classname attribute in the &#8218;ejbdoeclet&#8217; task is different in Xdoclet 1.2b2 compared to its predecessors. The class name stays &#8216;EJBDocletTask&#8217;, but the package structure has changed (xdoclet.modules.ejb instead of xdoclet.ejb). The cause for this is that Xdoclet used only one jar (xdoclet.jar) located in [XdocletInstallationDirectory]\lib in older versions, but Xdoclet 1.2b2 now uses a number of jars in the &#8216;lib&#8217; directory..

                    c. Certain attriubtes in the &#8218;ejbdoclet&#8217; tag are no longer supported by Xdoclet 1.2b2 (e.g. &#8216;sourcepath&#8217; and &#8216;classpathref&#8217;). Should those still be there it may happen that ant cannot find the class named under &#8216;EJBDocletTask&#8217;.

                    d. When using Xdoclet 1.2b2 the DTD-version for jbosscmp-jdbc.xml in buildxml has to be changed &#8216;manually&#8217; in build.xml. Xdoclet 1.2b2 only supports JBoss versions up to 3.0.

                    e. Example:

                    &#8230;
















                    ...

                    <!-- =================================================== -->
                    <!-- Replaces old dtds - xdoclet1.2b2 can only handle up to jboss 3.0, -->
                    <!-- so it uses old dtd - this task can be removed in future versions -->
                    <!-- =================================================== -->















                    5. After the build process jbosscmp-jdbc.xml should have entries that look like the following (MS SQL 2000 exmple &#8211; for MySQL the &#8216;class&#8217; attribute in the &#8216;entity-command-name&#8217; would be left out):

                    <cmp-field>
                    <field-name>orderId</field-name>
                    <column-name>OrderId</column-name>
                    <auto-increment/>
                    </cmp-field>

                    ...

                    <entity-command name="get-mssql-generated-keys"
                    class="org.jboss.ejb.plugins.cmp.jdbc.mssql.JDBCMsSQLCreateCommand">




                    I hope this helps. ;)

                    Daniel

                    • 22. Re: delay-database-insert-until and autogenerated PKs
                      trainjet

                      Daniel,

                      I have followed this instruction but got the following error message,
                      ...
                      xdoclet-generate:

                      BUILD FAILED
                      file:D:/JBoss/template/template/build.xml:138: The classpathref task doesn't sup
                      port the {2} attribute.


                      Is there anything wrong with my build.xml ?

                      here is my build.xml

                      ----------------

                      <?xml version="1.0"?>

                      <!-- ======================================================================= -->
                      <!-- Template build file -->
                      <!-- ======================================================================= -->



                      <!--
                      Give user a chance to override without editing this file
                      (and without typing -D each time they run it)
                      -->








                      Property "jboss.home" is not set. Please use the file
                      ".ant.properties" in this directory to
                      set this property. It must point to the directory which
                      contains the following directory: "deploy", "conf", "tmp"
                      etc.





                      Property "jboss.home" is set but it does not seem
                      to point to the right directory. The file "run.jar"
                      must be available at /bin.





                      Property "xdoclet.home" is not set. Please use the file
                      ".ant.properties" in this directory to
                      set this property. It must point to the root directory of
                      XDoclet distribution.





                      Property "xdoclet.home" is set but it does not seem
                      to point to the right directory. The file "xdoclet.jar"
                      must be available at /lib.



























                      <!-- Configuration used on JBoss 3 to run your server. There must be
                      a directory with the same name under "/server" -->











































                      <!-- =================================================================== -->
                      <!-- Generates the necessary EJB classes and deployment descriptors -->
                      <!-- =================================================================== -->



















                      <!-- AS 4/29/02 Do not validate XML files because JBoss 3.0 message driven will
                      report an wrong error because it uses the wrong jboss.dtd -->




                      <!-- =================================================================== -->
                      <!-- Compiles the source code -->
                      <!-- =================================================================== -->











                      <!-- =================================================================== -->
                      <!-- Creates the jar archives -->
                      <!-- =================================================================== -->

















                      <!-- =================================================================== -->
                      <!-- Compiles the WEB source code -->
                      <!-- =================================================================== -->












                      <!-- =================================================================== -->
                      <!-- Creates the war archives -->
                      <!-- =================================================================== -->













                      <!-- =================================================================== -->
                      <!-- Creates the client binary -->
                      <!-- =================================================================== -->








                      <!-- =================================================================== -->
                      <!-- Creates the client binary -->
                      <!-- =================================================================== -->


                      <!-- Convert the given paths to Windows -->










                      <!-- Convert the given paths to Unix -->




























                      <!-- =================================================================== -->
                      <!-- Creates the binary structure -->
                      <!-- =================================================================== -->




                      <!-- =================================================================== -->
                      <!-- Cleans up the current build -->
                      <!-- =================================================================== -->





                      <!-- =================================================== -->
                      <!-- Replaces old dtds - xdoclet1.2b2 can only handle up to jboss 3.0, -->
                      <!-- so it uses old dtd - this task can be removed in future versions -->
                      <!-- =================================================== -->
















                      ----------------

                      Thanks

                      • 23. Re: delay-database-insert-until and autogenerated PKs
                        bruynb

                        Interesting - I didn't seem to need the <auto-increment-template> tag...

                        • 24. Re: delay-database-insert-until and autogenerated PKs
                          trainjet

                          Alright, I finally got it compiled but have deployment problem.

                          Here is the error message,

                          Depends On Me:org.jboss.deployment.DeploymentException: Invalid XM
                          file:/D:/JBoss/jboss-3.2.1_tomcat-4.1.24/server/default/tmp/deploy/s
                          t/deploy/ejb-test.jar/41.ejb-test.jar!/META-INF/jbosscmp-jdbc.xml]

                          and here is my 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>

                          java:/MSSQLDS
                          <datasource-mapping>MS SQLSERVER</datasource-mapping>


                          <enterprise-beans>

                          <ejb-name>Address</ejb-name>
                          <create-table>false</create-table>
                          <remove-table>false</remove-table>
                          <table-name>address</table-name>

                          <cmp-field>
                          <field-name>id</field-name>
                          <column-name>AddressID</column-name>
                          <auto-increment/>
                          </cmp-field>

                          ...
                          <entity-command name="get-mssql-generated-keys" class="org.jboss.ejb.plugins.cmp.jdbc.mssql.JDBCMsSQLCreateCommand">
                          </entity-command>


                          </enterprise-beans>

                          </jbosscmp-jdbc>



                          • 25. Re: delay-database-insert-until and autogenerated PKs
                            trainjet

                            Very close ... it seems JBoss cannot understand <auto-increment> type. Error message

                            11:19:22,403 ERROR [XmlFileLoader] XmlFileLoader: Fi
                            3.2.1_tomcat-4.1.24/server/default/tmp/deploy/server
                            /70.ejb-test.jar!/META-INF/jbosscmp-jdbc.xml process
                            age: Element type "auto-increment" must be declared.

                            If I look at my standardjbosscmp-jdbc.xml, I do have it defined under ms sql2000.

                            <auto-increment-template>this_is_just_a_token</auto-increment-template>

                            any idea?

                            • 26. Re: delay-database-insert-until and autogenerated PKs
                              dabramov

                              Daniel,

                              First off, thanks so much for taking the time to post such detailed instructions.

                              I was using MS SQL and had a problem putting garbage in for the auto-increment template. It tries to construct SQL command from this string so garbage won't wor't. For MS SQL this does:
                              <auto-increment-template>?1 IDENTITY</auto-increment-template>

                              -Dan

                              • 27. Re: delay-database-insert-until and autogenerated PKs
                                dklehmann

                                Dan,

                                Thanks for the post.

                                Interesting. It worked for me, no matter what entry I inserted for the auto-increment-template tag... It doesn't quite make sense to me.

                                Your example is logical and probably right. Maybe there is a default entry that gets generated somewhere in the process...?



                                Qian,

                                Did you get your example to work with Dan's suggestion?



                                Daniel

                                • 28. Re: delay-database-insert-until and autogenerated PKs
                                  luminary

                                  > Very close ... it seems JBoss cannot understand
                                  > <auto-increment> type.

                                  I had this problem, and it appeared because my jbosscmp-jdbc.xml used the wrong DTD version; 3.0 instead of 3.2 (since the JBoss OpenTool for JBuilder doesn't support 3.2 yet). Check the first line of the file (the actual DTDs are available in docs\dtd).

                                  My jbosscmp-jdbc.xml, which I'm now able to successfully deploy, looks like this:

                                  <?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:/myDS
                                  <datasource-mapping>mySQL</datasource-mapping>
                                  <entity-command name="default"/>



                                  <enterprise-beans>

                                  <ejb-name>Xyz</ejb-name>
                                  <table-name>XYZ</table-name>
                                  <cmp-field>
                                  <field-name>xyzID</field-name>
                                  <column-name>xyzID</column-name>
                                  <auto-increment/>
                                  </cmp-field>
                                  ...
                                  <entity-command name="mysql-get-generated-keys"/>

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

                                  Hope this helps.

                                  • 29. Re: delay-database-insert-until and autogenerated PKs
                                    trainjet

                                    new 3.2 dtd setting did the trick!

                                    This was in Daniel's posting but somehow I did not do it right in my build.xml so that the build process was not replacing the 3.0 with 3.2.

                                    It is working now. Thank you very much for the help from all of you!