3 Replies Latest reply on Aug 6, 2004 4:39 AM by Alexey Loubyansky

    <insert-after-ejb-post-create>true</insert-after-ejb-post-cr

    ais Newbie

      Hi,

      Please give me an explanation of a strange behaviour of JBoss container.

      Suppose that I have in an entity bean A a cmr named B( that is not null in the database).

      In ejbCreate
      are set all cmp's of A, then
      in ejbPostCreate I have :
      set(B),

      where I get the following exception:
      javax.ejb.CreateException: Primary key for created instance is null.

      Of course in jboss.xml I have:

      <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>

      and also:

      <ejb-name>A</ejb-name>
      <configuration-name>INSERT after ejbPostCreate Container</configuration-name>
      <local-jndi-name>ejb/A</local-jndi-name>


      In jbosscmp-jdbc.xml

      <ejb-name>A</ejb-name>
      <table-name>A</table-name>

      <cmp-field>
      <field-name>xxx</field-name>
      <column-name>XXX</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>Id</column-name>
      </cmp-field>
      <entity-command name="mssql-fetch-key"/>


      Please give me some ideas, because I want to make all FK keys to be not null!

      Note that I am using JBoss3.2.4 and MSSQL server.

      TIA

        • 1. Re: <insert-after-ejb-post-create>true</insert-after-ejb-pos
          ais Newbie

          solved

          the problem is that you must set a dummy id in ejbCreate (this is a dummy id if the id will be generated by the database server )

          • 2. Re: <insert-after-ejb-post-create>true</insert-after-ejb-pos
            ais Newbie

            i wanted to post a more clear explanation.

            I was able to configure jboss to delay the insert after ejbpost create.

            In order to do this, the following lines must be added to jboss.xml:

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

            Another thing that must be done, is to mark the entity beans to use this configuration (this is also done in jboss.xml)

            The last thing that must be done, when the primary key is generated by the database server, is to set a dummy id for the entity bean in ejbCreate, something like: setId(new Integer(DUMMY_ID)); this will be overwritten by the database server with the right id. This hack must we done, otherwise an CreateException will be thrown (this is probably a jboss bug for now - not taking in account the fact that the primary key will be generated by the database server).

            HTH

            • 3. Re: <insert-after-ejb-post-create>true</insert-after-ejb-pos
              Alexey Loubyansky Master

              It's not safe in the current implementation. A real primary key must be available after ejbCreate and before ejbPostCreate. This is the spec by the way.