3 Replies Latest reply on Aug 6, 2003 8:05 AM by Rene

    JBoss UUIDKeyGenerator Example

    Jeovanny Newbie

      I am using JBoss 3.2.1 with Microsoft SQL Server 2000. I am using CMP and would like to create a primary key.

      I have purchased the CMP Documentation, it lends no help to using the UUIDKeyGenerator that JBoss offers. I have done several searches and can not find any help on generating a primary key using the JBoss services.

      Is it possible to do so? If so, could someone please give me a detailed response on how I might accomplish this?

      I am using the JBoss-IDE (XDoclet), so, if there is a way to specify it in the XDoclet parameters, that would be great.

      Also, do I have to put something in the ejbCreate?

      Any help would be greatly appreciated.

        • 1. Re: JBoss UUIDKeyGenerator Example
          Colin Wrinch Newbie

          Your jbosscmp-jdbc.xml should look something like the following, to use the MS SQLServer Command for auto-generated primary keys.

          <jbosscmp-jdbc>
          java:/SQLServer2000DS
          <datasource-mapping>MS SQLSERVER</datasource-mapping>

          <enterprise-beans>

          <ejb-name>TestTable</ejb-name>
          <create-table>false</create-table>
          <remove-table>false</remove-table>
          <table-name>TestTable</table-name>
          <cmp-field>
          <field-name>creationDate</field-name>
          <column-name>CreationDate</column-name>
          <not-null/>
          </cmp-field>
          <cmp-field>
          <field-name>modificationDate</field-name>
          <column-name>ModificationDate</column-name>
          <not-null/>
          </cmp-field>
          <!--Generate the primary key with an auto-increment column.-->
          <unknown-pk>
          <unknown-pk-class>java.lang.Long</unknown-pk-class>
          <field-name>testTableKey</field-name>
          <column-name>TestTableKey</column-name>
          <auto-increment/>
          </unknown-pk>
          <!--get-generated-keys must be defined in the commands section of the data source mapping-->
          <entity-command name="get-generated-keys"/>

          <created-time>
          <field-name>creationDate</field-name>
          </created-time>
          <updated-time>
          <field-name>modificationDate</field-name>
          </updated-time>


          ....

          And your JBOSS_HOME/server/default/conf/standardjbosscmp-jdbc.xml should have the following in the "defaults" section


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



          Hope that helps

          • 2. Re: JBoss UUIDKeyGenerator Example
            borislav Newbie

            Hi cwrinch,
            can you tell me how to configure it for Oracle9i and what value should I type then in home create method for the primary key

            (sorry for my poor english)

            Thank you in advance

            • 3. Re: JBoss UUIDKeyGenerator Example - Help for PostgreSQL, pl
              Rene Newbie

              I also purchased JBossCMP and the JBossAdminandDev_321 Book. Funny in the JBossAdminAndDev Book the CMP chapter is a bit bigger and has newer information, but ...

              Okay I found in the JBA&D book on page 620+ the definition of the <entity-command>. But I seem to need a full example for PostgreSQL.

              I'm working now since 2 days on bringing the cmp2 example to PostgreSQL instead on Hypersonic. The only problem I hope that is still open is the auto_generation of the primary key.

              PostgreSQL can create a sequence and primary key, if you declare the PK field as serial:
              eg:
              PostgreSQL:CREATE TABLE "project" (
              "idproject" SERIAL,
              "projectName" varchar(64),
              "budget" int4,
              "start" date,
              "end" date,
              CONSTRAINT "project_pkey" PRIMARY KEY ("idproject")
              );

              But I don't know how to define the <auto-increment-template> Tag to help JBoss to create the correct table definition.

              Nor do I completly understand how to use the UUIDKeyGenerator to let JBoss create the primary keys and use it with PostgreSQL!

              Maybe you could present it here. (Or maybe update the cmp2 example. PostgreSQL doesn't like the column name "desc" in the cmp2 example :-)