1 Reply Latest reply on Jul 9, 2003 6:03 AM by Marek Neumann

    CMR - ejbPostCreate - SQL not null Error

    userid Newbie


      I have an confusing Problem with JBoss 3.2.1.
      In my application I hava an one to many relationship. The relationship is implemented as foreign key mapping. In the database this foreign key is set to "not null" to avoid inconsistency.

      Entity User must have one relationship with entity Organisation. And Organisation can have multiple relationships with Users. So the User have an foreign key from Organisation.

      If I want to create an new User, first the ejbCreate method is called. There I set all CMP fields. Then I want to set the relationship in the method ejbPostCreate. Cause the ejb specification tell me to set the CMB fields in ejbCreate and the CMR fields in the ejbPostCreate method.

      But JBoss throw an error at ejbCreate, that he cannot create User, cause an SQL Error "Cannot insert a null into column (user.orgid)".

      I've deployed the same application to WebSphere and there, the Problem doesn't exists. It seems, that JBoss insert the new Record after ejcCreate but he should do it after ejbPostCreate.

      Is there an chance to tell JBoss to insert an new record after ejbPostCreate? Or to fix the Problem on an other Way. For other Application, I cannot remove the "not null" modifier from DB.

      All proposal are welcome!

        • 1. Re: CMR - ejbPostCreate - SQL not null Error
          Marek Neumann Novice

          Either you set your database to do deferred constraints, so that constraint are only checked at commit time (Oracle) or implement workaround by declaring <cmp-fields> for the foreign keys and setting the <cmp-fields> in ejbCreate():

          public Long ejbCreate(
          MessageLocal messageFk)
          throws CreateException, EJBException, SQLException
          public abstract void setMessageFk(Long messageFk);

          --> The spec forbids to set cmr fields in ejbCreate().