db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Emminger <e...@ericemminger.com>
Subject Re: working with foreign keys and null references
Date Mon, 05 May 2003 19:55:18 GMT
Stephen, Russell

Russell Simpkins wrote:
> its more a database issue.  read this
> http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=ddl-constraints.html#DDL-CONSTRAINTS-FK
> a foreign key constraint basically tells the db that the column value in the object table
must be a valid entry in the foreign table.
> As a work around, if my column does not always have to have a value (NULL o.k.) I don't
apply a foreign key constraint.  You can, in the case of Postgresql, apply a trigger.
> http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=sql-createtrigger.html
> your trigger would simply validate the value if and only if the value is not null.

In your Torque schema.xml file, use javaType="object" in all
references to the column. In other words, both the foreign key and the
primary key it references must use javaType object. I remember trying to
change just one and it failed.

Here's an example schema.

   <table name="app_customer" idMethod="native">
     <column name="customerId" type="INTEGER" required="true"
     <column name="currentSettingId" type="INTEGER" javaType="object"/>

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

   <table name="app_setting" idMethod="native">
     <column name="settingId" type="INTEGER" required="true"
primaryKey="true" javaType="object"/>

Ultimately, I changed all the primary and foreign keys in my schema to
javaType object, since that seemed to be the only cure-all solution.

----- setup -----
Torque 3.0
Turbine 2.2
TDK 2.2_01
PostgreSQL 7.3.2
Ant 1.5.1
Maven 1.0-beta-8
Java 1.4.1_01


View raw message