Hi,
I need some help on managing relationships on Entity Beans CMP 2.0.
I have two Entity Beans: Person and Gender. "Person" is stored on a
table that has a foreign key for the "Gender" table. "Person" has an
one-to-one relationship (CMR field) to "Gender". The foreign key
column for "Gender" in the "Person" table is NOT NULL.
The problem occurs when I try to create a new "Person" on the
database. The container tries to insert a NULL value on the foreign
key column and this causes a contraint exception. If I change the
foreign key column to allows NULL, everything works: the container
inserts a NULL value in the foreign key column but then updates the
column with the correct value.
Is this the only way to solve the problem? Can't I have NOT NULL
foreign key columns for CMR fields?
Thanks in advance,
Joan
Frank Langelage - 25 May 2004 00:00 GMT
> Hi,
>
[quoted text clipped - 18 lines]
>
> Joan
AFAIK there are only AppServer specific solutions.
JBoss supports flag
<insert-after-ejb-post-create>false</insert-after-ejb-post-create>
in the container configuration. Default value is false.
Other Servers will support similar solutions.
Setting this to true delays the SQL-insert until ejbPostCreate() is
called. There you have to set the gender in your case.
If you want to do setting the gender later with setGender(...) this
probably won't help you.
Then the only solution will be to allow NULL values for this field.
Regards
Frank