5 Replies Latest reply on May 7, 2004 5:32 AM by sesques

    Unknown-pk usage ?

    sesques Novice

      Further to several topics on this forum, I ask myself a simple question:
      What use for unknown-pk tag ?

      I'm new to JBoss (about 6 month) and I was WebLogic before. When I migrate my application from Weblogic to JBoss, I had 2 problems:
      - Database primary key generation mapped to entity beans
      - Not null foreign keys for entity bean creation.
      I debate many time on several forums (with Nukes developpers also) and I defend the "unknow-pk" tag because this tag save my migration and I was convinced that it was the whole solution for database generated keys.

      Recently, I bought the the doco and I look attentively to the CMP engine. But I cannot find more details about this tag that you can find in the XDoclet documentation. But in the DOCO, JBoss gives 2 simple configuration examples, one with a known pk cmp-field and the other with an unknown-pk field. And the worse is that when I try to implement my database generated keys with a known cmp-field, IT WORKS !.
      The first time I tried to do that way, IT DOESN'T ! Certainly I made mistakes, and I search on this forum and someone gives me the unknown-pk solution.

      So, I ask a simple question: What is the unknown-pk tag usage (except not declaring a known cmp-field for the primary key) ?

      Pascal


        • 1. Re: Unknown-pk usage ?
          sesques Novice

          Anybody ?

          • 2. Re: Unknown-pk usage ?
            roger_cmu Newbie

            Hi Pascal,

            My comments are not answers to your questions. Rather I am asking the same question in a different fashion.

            Look at the quesion posted by author 'KarstenTS':


            I'm trying to get an CMP EntityBean startet that should have an auto-generated primary-key, an auto-incremented Integer.


            I'm not sure why resort to unknown-pk to solve the issue of
            1- auto generated primary key
            2- auto increment integer

            I had similar situation and it was solved without resorting to unknown-pk. The solution was posted at jboss forum at javaranch http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=63&t=000783.

            I feel I am missing something here because I see a lot of postings related to unknown-pk trying to solve the above mentioned issues.

            Any thoughts.

            - Roger

            • 3. Re: Unknown-pk usage ?
              sesques Novice

              Thanks Roger,

              I agree with you. The auto generated primary key issue is solved by:

              1) the @jboss.persistence auto-increment = "true" tag for the primary key cmp field.
              2) the @jboss.entity-command name = "(Database specific)" in the bean definition.

              But it works also with:
              1) @jboss.unknown-pk ... auto-increment="true" in the bean definition
              2) @ejb.pk class = "java.lang.Object" in the bean definition
              3) the @jboss.entity-command name = "(Database specific)" in the bean definition.
              4) Not defining a cmp-field for the primary key.

              BTW, JBoss don't care about the ejbCreate return type. In both cases, I return a java.lang.Object and it works fine.

              So the question is what's the difference, and what is the uses cases for each method ?

              I think that only a JBoss guy can respond ;-)

              Pascal



              • 4. Re: Unknown-pk usage ?
                Alexey Loubyansky Master

                There is a paragraph in the spec 'special case: unknown priamry key'.
                The point is that you might not know for sure the pk (which is automatically generated) type in the deployment environment and you don't care.
                But in practice it seems to be a rare case and you can make any unknown pk to be a 'known' one and have a typed accessor.

                • 5. Re: Unknown-pk usage ?
                  sesques Novice

                  Thanks very much Alex.
                  This is more clear for me.

                  Pascal