12 Replies Latest reply on Aug 7, 2002 10:32 AM by lkmanda

    Database foreign keys must be "not null"?

    mdefreitas

      After much hair pulling (a CMP workbook that didn't correspond to the DTD, etc) and research into the forum archives, I finally got a simple container managed relation example to work.

      My example was the classic 1:N relation of an order:lineitem. I had the foreign key in the lineitem table (which referenced the order table) set up as NOT NULL. When I tried to add a lineitem to an order, I got an error that a null was being inserted into a non-null field. After a bit of thinking I removed the NOT NULL restriction on the foreign key and it worked.

      Is this the way it has to be? It would seem that making the foreign key NOT NULL is useful for database integrity.

      Also, I assume two database hits are being used (one to insert the lineitem with a null foreign key and one to update the foreign key). I guess this is the way it has to be (given the CMR sematics)?

      This is my first attempt at using Entity Beans and I've got to admit the overhead scares me. Is there a good book someone can recommend on the "right way" to use entity beans? I guess the right way is vendor dependant? Sure would be nice to have a JBoss performance guidance manual.

      Sorry for the newbie ramblings.

      Thanks for any insight.