db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fox <Thomas....@seitenbau.net>
Subject RE: Define a Foreign Key with a One-to-One mapping
Date Tue, 31 May 2011 18:15:11 GMT
> How do I define a foreign key in my Torque schema with a one-to-one
> mapping ?  No matter what I do I always seem to end up with a one-to-many

> relationship ?

There is no support on the java side for a one-to-one relationship (meaning
that a one-to-one relationship is a special case as a
one-to-many-relationship and the generated java code always reflects the
more general one-to-many case)

But you can write the code for a one-to-one relationship yourself:
On the database side, a one-to-one relationship is a non-nullable foreign
key column with a unique index on the foreign key column. All of this can
be defined in the torque schema, e.g. as
...
<column name="journeySetID" required="true"... />
<foreign-key foreignTable="styledJourneys">
  <reference local="journeySetID" foreign="journeySetID"/>
</foreign-key>
<unique>
  <unique-column name="journeySetID"/>
</unique>
...

Then, as you know thatyou have enforced a one-to-one relation on the
database side, you can refelct this knowledge on the java side by adding
getters and setters to your java code which map the n side list to a 1 side
simple getter and setter.

     Hope that helps,

          Thomas


---------------------------------------------------------------------
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