3 Replies Latest reply on Mar 29, 2004 4:29 AM by Alexey Loubyansky

    UPDATE after INSERT in CMR

    mkyaj Newbie

      Hi,

      To put my problem with an example i have a CMR USER(1) -ADDRESS(m).
      When i create an User, it will create the corresponding Addresses(say 3 different addresses for this instance) also.
      It is calling
      INSERT INTO ADDRESS(field1,field2,USER_FK) VALUES(?,?,?).
      INSERT INTO ADDRESS(field1,field2,USER_FK) VALUES(?,?,?).
      INSERT INTO ADDRESS(field1,field2,USER_FK) VALUES(?,?,?).

      and after that it is again calling
      UPDATE ADDRESS set USER_FK=? WHERE ID=?
      UPDATE ADDRESS set USER_FK=? WHERE ID=?
      UPDATE ADDRESS set USER_FK=? WHERE ID=?

      How to stop updating immediately after creation?

      Murali.

        • 1. Re: UPDATE after INSERT in CMR
          Alexey Loubyansky Master

           

           <container-configurations>
           <container-configuration extends="Standard CMP 2.x EntityBean">
           <container-name>INSERT after ejbPostCreate Container</container-name>
           <insert-after-ejb-post-create>true</insert-after-ejb-post-create>
           </container-configuration>
           </container-configurations>
          


          • 2. Re: UPDATE after INSERT in CMR
            mkyaj Newbie

            Hi,

            I think that flag is to specify whether the insert has to be called before ejbPostCreate() or after ejbPostCreate();
            Possible values are:
            false - the default value, INSERT will be executed after ejbCreate but before
            ejbPostCreate;
            true - INSERT will be executed after ejbPostCreate.

            I tried by changing that to - true. I am getting an exception
            javax.ejb.CreateException: Primary key for created instance is null.

            Thanks,
            Murali.

            • 3. Re: UPDATE after INSERT in CMR
              Alexey Loubyansky Master

              Probably, you are using primary key generation entity-command and the primary key is generated at INSERT time. If so, of course, it won't work.
              As a workaround, you could use some entity-command that generates keys before INSERT.
              Sorry, but that's the spec.