You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Jim Menard <ji...@io.com> on 2003/12/18 15:48:30 UTC

Nullable foreign keys

I'm trying to understand how nullable foreign keys work in Torque.

I have a database table ("member") with a foreign key ("language_id") 
to another table. The foreign key may be null. When I load a member, 
it's language is null. Actually, the language_id seems to be set to 0, 
which really confuses me.

When I try to save the member with no changes, I see the exception

ERROR:  member_fk_2 referential integrity violation - key referenced 
from member not found in language

Of course not! There is no language record with id 0.

It looks like NULL foreign keys are stored in Torque as 0, not as NULL. 
This seems evil to me. When the member tries to save itself, it tries 
to save 0 into the language_id field, which is not a legal foreign key 
value. Why does it try to save 0 instead of saving NULL?

(I can't figure out how to search the mailing list archives. I clicked 
on the "archive" link in the Torque documentation, but that URL doesn't 
seem to be good.)

Thank you for your help.

Jim
-- 
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Master, does Emacs have the Buddha nature?" the novice asked.
"I don't see why not. It's got bloody well everything else."
     -- John Fouhy


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Nullable foreign keys

Posted by Jim Menard <ji...@io.com>.
> You must put in the sschema.xml that language_id has a 
> javaType='Object'.   This is the only way to put a null in a column 
> with torque.

Thank you, Felipe and Adrian, for your answers.

Jim
-- 
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"All those who believe in psychokinesis raise my hand." -- Anon.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Nullable foreign keys

Posted by Felipe Ramos <fr...@tissat.es>.
You must put in the sschema.xml that language_id has a 
javaType='Object'.   This is the only way to put a null in a column with 
torque.

Jim Menard wrote:

> I'm trying to understand how nullable foreign keys work in Torque.
>
> I have a database table ("member") with a foreign key ("language_id") 
> to another table. The foreign key may be null. When I load a member, 
> it's language is null. Actually, the language_id seems to be set to 0, 
> which really confuses me.
>
> When I try to save the member with no changes, I see the exception
>
> ERROR:  member_fk_2 referential integrity violation - key referenced 
> from member not found in language
>
> Of course not! There is no language record with id 0.
>
> It looks like NULL foreign keys are stored in Torque as 0, not as 
> NULL. This seems evil to me. When the member tries to save itself, it 
> tries to save 0 into the language_id field, which is not a legal 
> foreign key value. Why does it try to save 0 instead of saving NULL?
>
> (I can't figure out how to search the mailing list archives. I clicked 
> on the "archive" link in the Torque documentation, but that URL 
> doesn't seem to be good.)
>
> Thank you for your help.
>
> Jim


-- 
------------------------
Felipe Ramos
Tissat SA
C/ Orense 34-9ยช
28020 Madrid
Tel: (+34) 91 4175913 
Fax: (+34) 91 4172914
Mail: framos@tissat.es
------------------------




---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org