Hm, ok, thx for your fast answer.
I don't like this, because it is possible that foreign key fields are
not initialized if they are not required.
Will torque initialize those fields with 0?
Patrick Carl wrote:
> Hi,
>
> in the c1.getClass2() Torque checks if the foreign key is intialized.
> To do so, it checks if its value is not zero. As integers are
> primitives in java, they cannot be null but have a value of zero
> if they are not initialized.
>
> I see no other way to check if a foreign key is initialized,
> than to check if its vaue is not null.
>
> Patrick
>
> On Fri, February 17, 2006 08:48, Patrick Herrmann wrote:
>> Hi,
>>
>> I tried torque and run into problem with references.
>>
>> Look at this shema:
>>
>> <table name="CLASS_1">
>> <column name="PK" primaryKey="true" type="INTEGER"/>
>> <column name="NAME" type="VARCHAR" required="true"/>
>> </table>
>>
>>
>> <table name="CLASS_2">
>> <column name="PK" primaryKey="true" type="INTEGER"/>
>> <column name="NAME" required="true" type="VARCHAR"/>
>> <column name="FK" required="true" type="INTEGER"/>
>>
>> <foreign-key foreignTable="CLASS_1" name="CLASS_1">
>> <reference foreign="PK" local="FK"/>
>> </foreign-key>
>> </table>
>>
>>
>>
>> The primary keys can be 0. When I store two objects like this:
>>
>> Class1 c1 = new Class1();
>> c1.setPk(0);
>> c1.save();
>>
>> Class2 c2 = new Class2();
>> c2.setPk(0);
>> c2.setClass1(c1);
>> c2.save();
>>
>>
>> And then do the this query later:
>>
>> Class2 c2 = Class2Peer.retrieveByPK(0);
>> Class1 c1 = c2.getClass2(); <--- null
>>
>> , then c1 is null.
>>
>> When Class1 primary key is non 0 then it works fine.
>>
>>
>> Do I really need to use another primary key with, for example, auto
>> increment to avoid this problem?
>> Class1.retrieveByPK(0) works fine, why not c2.getClass2()?
>>
>>
>> Thanks,
>> Patrick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: torque-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
|