4 Replies Latest reply on Apr 10, 2003 3:56 PM by huri

    allow null cmr fields

    Weiqing Huang Newbie

      hi there,

      in ejb2.0, since one cannot set the cmr field in ejbCreate, i am seeing errors like "column foo_id_fk in table barentity cannot be null" when creating a new ejb bar, which has a relationship to ejb foo.

      the error only happens on a sybase we are using, but not on oracle. i checked sybase schema and apparently the foreign key column is marked as "null not allowed". if i change it to allow null, everything works.

      my question is: is there a ejb/jboss standard way of controlling the fk column not-null property just like not-null in cmp?

      also is there a way to work around the problem if the schema just disallows null value? i heard there is a delay-create option in weblogic. anything similar in jboss?

      thanx a lot.

        • 1. Re: allow null cmr fields
          Maxim Newbie

          This problems exists in jboss 3.0.4 and here is the description of this issue in the standard jboss documentation on CMP.
          The current implementation of JBossCMP inserts a row into the database for a new entity between ejbCreate and ejbPostCreate. Since the
          EJB specification does not allow a relationship to be modified until ejbPostCreate, a foreign key will be initially set to null. There is a similar
          problem with removal. This limitation will be removed in a future release.
          Was it solved in 3.0.6? I'm going to try it now.
          --max.

          • 2. Re: allow null cmr fields
            Weiqing Huang Newbie

            i tried jboss-3.2.0RC5 and it didn't work.

            another part of the question is that is there a way to configure db schema so that null foreign key is allowed?

            • 3. Re: allow null cmr fields
              Maxim Newbie

              I think that the only way to work around this limitation is to set nullable f. keys. I hate doing this but I don't see any other solution.
              I found another problem - my application stopped working after migration from 3.0.4 to 3.2RC4. It deployes CMP beans, but at runtime on my findBy... call it throws sql exception - relation A14_users (one table in PostgreSQL 7.3) not found...

              --mk.

              • 4. Re: allow null cmr fields
                huri Newbie

                In Oracle, you can use deferred NULL constraints, which checks the constraint at commit time. Don't know if other databases have something similar.

                e.g. CREATE TABLE CLIENT ( ...
                STATUSID NUMBER (20) CONSTRAINT CLIENT_NN_STATUSID NOT NULL INITIALLY DEFERRED, ...