Discussions

EJB programming & troubleshooting: ejbPostCreate in JBoss :: NEED HELP

  1. ejbPostCreate in JBoss :: NEED HELP (3 messages)

    Hi there,

    this is pretty urgent and I'm stuck. I'm using Jboss 4.0 DR4.

    I set up two tables named Contract and Type. The Contract table has a reference to the Type table (foreign key relationship). I set up a CMR relationship that works fine, except when I try to insert a new Contract into the database.

    The Errormessage reads:

    17:05:56,736 ERROR [Contract] Could not create entity
    java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO CONTRACT (ID, NAME, TYPE, CLIENT, STATUS, type) VALUES (10, NULL, 0, 0, 0, NULL)]
    at org.hsqldb.Trace.getError(Unknown Source)
    at org.hsqldb.jdbcResultSet.<init>(Unknown Source)
    at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
    at org.hsqldb.jdbcConnection.execute(Unknown Source)
    at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
    at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)

    I initialize the primary key field in the ejbCreate method and the relationship in the ejbPostCreate method, but that method apparently never gets called, because the ejbCreate method is executed first and then Jboss generates the above error message.

    The create methods look like this:

    /**
    * @return
    * @throws CreateException
    *
    * @ejb.create-method
    */
    public Integer ejbCreateContract(Integer id, ContractTypeLocal ctl) throws CreateException{
    setId(id);
    return null;
    }

    public void ejbPostCreateContract(Integer id, ContractTypeLocal ctl){
    setContractTypeCMR(ctl);
    }

    I'm pretty stuck and don't really know what to do.
    thanks
    matt

    Threaded Messages (3)

  2. found the Solution[ Go to top ]

    The bean creation process has to be delayed. I read that in earlier posts (about weblogic), but didn't know if that was possible in jboss as well.
    I found the solution in the following post:

    http://www.jboss.org/index.html?module=bb&op=viewtopic&t=43591

    I added the following code to the standardjboss.xml configuration-file

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

    and used the XDoclet tag

    @jboss.container-configuration name="INSERT after ejbPostCreate Container"

    in the contract bean.

    For now :) everything works fine

    cheers
    matt

    btw - this works with simple and compound primary keys, where part of the key is a foreign key to another table
  3. found the Solution[ Go to top ]

    I guess you are using CMP... The error is perfectly reasonable, in my opinion, if your fk field in contract table is not nullable... which should make you wonder about your design. Can a contrant have no type? If so, the fk field should be nullable, and the insert must work with a null Type in ejbCreate.

    Regards
  4. CMR fields[ Go to top ]

    Hi Martin,

    the contract type field is nullable (CMP). The reason this has to be done is that I'm using CMR (Container Managed Relationship) and that field has to be set when I create a new Contract, otherwise I would get an error.

    The relationsship is one-to-many (type - contract). The dependent side of the relationship has to be set I suppose.

    cheers
    matt