db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remke Rutgers <Remke.Rutg...@brightalley.nl>
Subject RE: Saving a tree
Date Thu, 15 May 2003 08:08:55 GMT
Hi Malte,

My guess is that your property PreviousExpiryDataItemID is an int in your
Torque objects (primitive type, not an object type). Since there is no null
concept for the primitive types, I think there is no way to have Torque save
this property as null. I think it will work if you use object Integer types
in your Torque objects. (I don't know the exact syntax in the schema, but
that should be easy to find in the docs)

Remke

-----Oorspronkelijk bericht-----
Van: Malte Stien [mailto:malte@stien.de]
Verzonden: donderdag 15 mei 2003 7:09
Aan: torque-user@db.apache.org
Onderwerp: Saving a tree


Hi,

I have got a table that represents a tree, i.e. it has a
"parent"-relationship 
with itself. Some of the rows have a foreign-key pointing to another row in 
the same table which represents the "parent" of a particular row. However, 
some of the rows do not have a parent and thus are "roots".

I represented that in the schema by setting the "required"-field of the 
foreign key to false.

  <table name="ExpirableDataItem" description="">
    <column
      name="ExpirableDataItemID"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="ID of the ExpirableDataItem"/>
    <column
      name="PreviousExpiryDataItemID"
      required="false" <==============================================
      primaryKey="false"
      type="INTEGER"
      description=""/>
    <foreign-key foreignTable="ExpirableDataItem">
      <reference
        local="PreviousExpiryDataItemID"
        foreign="ExpirableDataItemID"/>
    </foreign-key>
  </table>

The database schema seems to be alright. I can successfully perform manual 
inserts in the Postgresql database (using psql) that look like:
- insert into expirabledataitem (expirabledataitemid) values (5004);
- insert into expirabledataitem (expirabledataitemid, 
previousexpirydataitemid) values (5005, 5004);

But the problem is that I cannot create such an object in Torque without 
setting the previousexpirydataitemid and then save it. I get the error 
message:
- expirabledataitem_fk_1 referential integrity violation - key referenced
from 
expirabledataitem not found in expirabledataitem

I have the suspicous that Torque tries to save always ALL values of an
object 
(whether they have been set or not) and that save tries to set the value for

previousexpirydataitemid to 0 and since there is no such object the save 
fails. I tried to emulate that manually and got the same error message which

supports my theory.
- insert into expirabledataitem (expirabledataitemid, 
previousexpirydataitemid) values (5007, 0);
ERROR:  expirabledataitem_fk_1 referential integrity violation - key 
referenced from expirabledataitem not found in expirabledataitem

Any ideas how to save root elements of a tree? I don't really want to use a 
dummy root element that is always there.

Thanks for any suggestions.
Malte.


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

Mime
View raw message