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 Bernardo Arlandis Mañó <be...@ya.com> on 2003/01/21 13:52:42 UTC
Problem with foreign keys
Hi, it's the first I post to this list. I've started doing development with
turbine and torque and I have been able to do well by myself, but now I'm a
little lost with this problem.
I'm using for my trainning the tdk2.2.1_01 which uses torque3.0.
I've defined something like this:
<database name="data">
<table name="TABLE1">
<column name="ID" required="true" primaryKey="true" type="INTEGER"/>
<column name="NAME" required="true" size="32" type="VARCHAR"/>
</table>
<table name="TABLE2">
<column name="ID" required="true" primaryKey="true" type="INTEGER"/>
<column name="NAME" required="true" size="255" type="VARCHAR"/>
</table>
<table name="table3" idMethod="idbroker">
<column name="ID" required="true" primaryKey="true" type="INTEGER"/>
<column name="FK1" type="INTEGER"/>
<column name="FK2" type="INTEGER"/>
<foreign-key foreignTable="TABLE1" name="FK_FK1">
<reference local="FK1" foreign="ID"/>
</foreign-key>
<foreign-key foreignTable="TABLE2" name="FK_FK2">
<reference local="FK2" foreign="ID"/>
</foreign-key>
</table>
</database>
Doing it this way I get duplicated methods for the foreign key columns, one for
the key and one another for the object. So I've tried taking away the column
definitions of the foreign keys changing table3 like this:
<table name="table3" idMethod="idbroker">
<column name="ID" required="true" primaryKey="true" type="INTEGER"/>
<foreign-key foreignTable="TABLE1" name="FK_FK1">
<reference local="FK1" foreign="ID"/>
</foreign-key>
<foreign-key foreignTable="TABLE2" name="FK_FK2">
<reference local="FK2" foreign="ID"/>
</foreign-key>
</table>
But now I get a NPE:
java.lang.NullPointerException
at
org.apache.torque.engine.database.model.Database.doFinalInitialization(Database.java:444)
at
org.apache.torque.engine.database.model.AppData.doFinalInitialization(AppData.java:313)
at
org.apache.torque.engine.database.model.AppData.getDatabase(AppData.java:221)
at
org.apache.torque.task.TorqueDataModelTask.initControlContext(TorqueDataModelTask.java:350)
I hope someone can give me a hint as I've been unable to find an explanation
looking at the docs and examples.
Thank you.
Regards.
--
Bernardo
Re: Problem with foreign keys
Posted by Bernardo Arlandis Mañó <be...@ya.com>.
I'll answer myself as someone may find it useful.
I found out it was failing because the name of the column with the
foreign key and the name of the foreign table can't be the same with
torque. That's why I got methods with identical names.
Regards.
--
Bernardo