You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Eric Emminger <er...@ericemminger.com> on 2002/11/07 19:05:28 UTC

working with foreign keys and null references

Using TDK 2.2 RC1 and PostgreSQL, how do you save a Business Object with
null foreign-key references?

I have a Customer object that references a Setting. When the Customer is
created, the Setting is null because the Customer has not set it.

This worked in TDK 2.1 with MySQL. In the current setup of TDK 2.2 RC1
with PostgreSQL, Customer.save() throws the following error.

Exception:  org.apache.torque.TorqueException: ERROR:  app_customer_fk_2
referential integrity violation - key referenced from app_customer not
found in app_setting

Here is the schema.
  <table name="app_customer" idMethod="native">
    <column name="customerId" type="INTEGER" required="true"
primaryKey="true"/>
    <!-- ... -->
    <column name="currentSettingId" type="INTEGER"/>
    <!-- ... -->

    <foreign-key foreignTable="app_setting">
      <reference local="currentSettingId" foreign="settingId"/>
    </foreign-key>
  </table>

  <table name="app_setting" idMethod="native">
    <column name="settingId" type="INTEGER" required="true"
primaryKey="true"/>
    <!-- ... -->
  </table>

Complete setup is
TDK 2.2 RC1
PostgreSQL 7.2
Java SDK 1.4.0_01
Ant 1.5.1
Linux

Thanks for your help!

Eric

-- 
Eric Emminger
eric@ericemminger.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>