4 Replies Latest reply on Sep 1, 2003 5:13 AM by maciek

    to pass a pk value to ejbCreate or not to pass?

    maciek

      hello

      I am wondering whether it is necessary to pass pk value to ejbCreate method. In most examples that I have seen pk is passed.
      However when a new row is inserted , a pk is something artificial, so would not it be better to let cmp find pk on its own(e.g by using some other stateles session bean )?
      then ejbCreate would get only "real" data

      what am I missing? :)

      regards

      maciek zywno

        • 1. Re: to pass a pk value to ejbCreate or not to pass?
          takenori

          Hi,

          We're using auto-increment feature
          so that we don't need to pass the pk value
          in ejbCreate method.

          Takenori

          • 2. Re: to pass a pk value to ejbCreate or not to pass?
            maciek

            ok

            So let's narrow my xample to the situation where I decided to use some stateless session bean to generate pk's.
            (Is such a method used by you?)
            then again should that session bean method getNextPk be invoked by cmp in its create method or pk_generation-session bean should be invoked earlier by a service session bean that is responsble for "adding rows" action?

            regards

            • 3. Re: to pass a pk value to ejbCreate or not to pass?

              Hi,

              I use Autonumber factory for auto-increment (just to keep things portable).
              I enter ejbCreate() with no pk and call the factory.getNextInteger() in that method.
              This works fine. So I imagine you can do the same with your session bean.

              The rule is that before you leave ejbCreate you should have set your pk and no other fields (eg. setPk(sessionBean.getNextInteger())). If you need to set any other fields then you should set them in ejbPostCreate().

              kv.

              • 4. Re: to pass a pk value to ejbCreate or not to pass?
                maciek

                thanks, but one more equestion about that in ejbCreate only pk field should be set

                (actually i recenlty read that in ejbPostCreate one should set CMR fields in ejbPostCreate not in ejbCreate)

                you said that in ejbCreate only pk field

                why not everything just in ejbCreate? is it a mater of style?
                (maybe I am asking about something obvious :)

                thanks

                maciek zywno