-
1. Re: cmr and database constraint
tommyg Mar 18, 2003 12:00 PM (in response to benholland)With JBoss3.0.x foreign keys can not be null, as far as I know. JBoss3.2 RC3 is different though. If I have a situation like you do, I can describe each field-even foreign key fields-using setX and getX. I can then use a 'many' table that has a foreign key constraint of not null.
Then, I simply add the many table using ejbCreate and in my ejbCreate method I populate the foreign key value. This allows me to use CMP, CMR with a database that requires the foreign key to be null.
Anybody have an idea on when JBoss3.2 will hit final? -
2. Re: cmr and database constraint
tommyg Mar 18, 2003 12:07 PM (in response to benholland)That is, with JBoss3.0.X foreign keys must be NOT NULL.
-
3. Re: cmr and database constraint
carlolf Mar 22, 2003 12:03 PM (in response to benholland)I discovered the same problem with a simple cmr 1:n example i have tried to get run. Obviously JBoss does not generate a value for the foreign key needed on the dependant table in the sql statement.
I was very shocked, because i thought this is one of the simplest task you can do with EJB2.0 cmr.
Given this experience, i do not understand, why the test examples with cmr are running without errors.
Is there a solution or patch available? -
4. Re: cmr and database constraint
benholland Mar 24, 2003 7:51 AM (in response to benholland)I got round my problem by using indexes and allow null in my sql. Here is the mysql schema:
CREATE TABLE mvdc_customer_details(
pk_id INT NOT NULL,
fk_customer_id INT NULL,
email_address VARCHAR(50) NOT NULL,
INDEX cust_ind(fk_customer_id),
PRIMARY KEY (pk_id),
FOREIGN KEY (fk_customer_id) REFERENCES mvdc_customer (customer_id) ON Delete SET NULL
) TYPE=INNODB;
Jboss will set the fk fields null when I do a delete.
And it works. now on to one to many which doesnt!
Ben. -
5. Re: cmr and database constraint
tommyg Mar 24, 2003 9:18 AM (in response to benholland)One workaround or solution (may not be the best) is to use JBoss3.2RC3. And use it this way.
For add: In a one-to-may relationship, add the 'one' table with ejbCreate, then add the 'many' table with ejbCreate-populating the foreign key field in the ejbCreate method. Because with JBoss3.2RC3 you can now define setX and getX for foreign key fields.
For update and delete it should be how you would expect it. -
6. Re: cmr and database constraint
joerk Apr 3, 2003 7:39 AM (in response to benholland)Hello,
where can I find information how JBoss3.2RC4 handels CMR?
add: I set the relation fields in ejbPostCreate() - OK, works fine
update: OK, works fine
delete: JBoss first want to update the foreign key field to NULL - UPDATE table set FK_ID = null where ID = X - The Database fires the NOT NULL constraint. I have no idea who to handel the remove() ? Any hints ?
Thanks Joerk