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.
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?
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...
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, ...