Home > Archive > Java Beans > May 2004 > Relationships on EJB CMP 2.0
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Relationships on EJB CMP 2.0
|
|
|
| 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 2004-05-24, 8:38 pm |
| Joan wrote:
> 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
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
|
|
|
|
|