6 Replies Latest reply on Dec 5, 2002 12:01 PM by Allen Walker

    Unknown primary key class

    Tim Hoverd Newbie

      I'm trying to get the latest version of the Petstore (1.3.1) going with JBoss/CMP. I've struck a problem in that some, actually most, of the beans in it now are defined without a declared primary key class. (See section 10.8.3 of the EJB 2.0 and 2.1 specs.)

      The effect of this is to cause confusion when there are associations between beans. (Not surprising as there's no obvious way of creating a foreign key reference.)

      So, am I missing something, or do I really have to go through all the JBoss code adding.inventing primary keys?



        • 1. Re: Unknown primary key class
          Maxim Drobintsev Newbie

          Try the latest JBoss 3.2 beta2 - it seems to support Unknown primary key class

          • 2. Re: Unknown primary key class
            Harald Newbie

            I am working on the same problem and I have found two intresting posts regarding this, here is the short
            version. Good luck with the configuration.


            And yes of course you need the JBoss 3.2 beta2 to get it to work


            JBossCMP becomes cooler. Now it supports Unknown primary keys (Refer to EJB2.0 spec 10.8.3 for details).

            To make use of this feature, entity beans must have prim-key-class declared as java.lang.Object and no primkey-field in ejb-jar.xml.
            To set up unknown primary key, the new optional unknown-pk element is used in jbosscmp-jdbc.xml. (See jbosscmp-jdbc_3_0.dtd for details).
            If unknown-pk element is omitted in jbosscmp-jdbc.xml, the default one from standardjbosscmp-jdbc.xml will be used.
            The default (and the only for now) key generator factory is UUIDKeyGeneratorFactory. It's deployed as a service and bound to the global JNDI context.
            Other key generator factory implementations are welcome!

            The feature is available in CVS HEAD version.

            Alex Loubyansky

            JBossCMP now provides some new ways to setup and create entity beans.
            It is based on so called entity commands.
            First some working examples (snippet from jbosscmp-jdbc.xml):


            <!-- auto-incremented primary key (jdk1.3/1.4) for now supported only for MySQL. -->
            <!-- entity command to create the entity -->
            <entity-command name="mysql-get-generated-keys"/>

            <!-- unknown primary key generated with SQL statement -->
            <entity-command name="pk-sql"/>
            <!-- pk-sql generated unknown-pk; overriding default sql
            <entity-command name="pk-sql">
            SELECT SEQ_2279_1.nextval FROM DUAL
            <!-- mysql generated unknown-pk
            <entity-command name="mysql-get-generated-keys"
            <!-- the use of key generator for unknown-pk
            <entity-command name="key-generator"

            The general syntax of entity-command is:
            <entity-command name="CommandName"

            Only the 'name' is required.
            You can check the list of available commands in
            standardjbosscmp-jdbc.xml in entity-commands element.
            The default entity command is specified in 'defaults' element and can
            be overriden in each entity element as above.
            If entity-command in the entity provides 'class' or 'attribute' it
            overrides the corresponding element of in the known command.

            For now the feature is available in HEAD version.

            PS: templates for non-MySQL auto-increment SQL statements are welcome!!!


            • 3. Re: Unknown primary key class
              Elmar Henne Newbie

              I have Petstore 1.3.1 now running on JBoss 3.0.2, but to do so I had to define explicit primary keys for those tables. I have started a new topic where I am presenting my experiences:
              "Running PetStore 1.3 on JBoss 3.0" (http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/

              • 4. Re: Unknown primary key class
                Allen Walker Newbie

                I could not find the code for the 'mysql-get-generated-keys' entity command. Is this provided in jboss3.2.0-beta2?


                • 5. Re: Unknown primary key class
                  Allen Walker Newbie

                  Disregard, I found it.

                  • 6. Re: Unknown primary key class
                    Allen Walker Newbie

                    I have a problem. I am using MSSQLServerv7 identity columns for my PK. However I found a class:


                    So as long as my driver is jdbcv3 compliant, this should work yes? (I am in the process of acquiring a jdbcv3 driver).