Well yes, If you set a foreign key that points to an id that does not exist
you will get an exception when performing save. But the setting of the value
itself, in java, can never throw an exception. Here is an example of a
set-method. All it does is it assigns new values to class attributes and
comparing the parameter with existing values.
public void setCompanyId(int v) throws TorqueException
{
if (this.companyId != v)
{
this.companyId = v;
setModified(true);
}
if (aCompany != null && !(aCompany.getId() == v))
{
aCompany = null;
}
}
/Ludwig
-----Original Message-----
From: Thomas Vandahl [mailto:[email protected]]
Sent: den 16 mars 2010 19:04
To: Apache Torque Developers List
Subject: Re: set(Foreign key) throws exception for no reason?
Ludwig Magnusson wrote:
> Hi!
>
> When torque generates set methods for foreign keys, the methods thorws a
> TorqueException.
>
> Why is this? There is nothing in the methods that throws a TorqueException
> and removing the throws clause does not generate a compiler error.
Setting a foreign key could cause a consistency problem with the
database. If the record the foreign key points to does not exist, you
will get an exception on save() (depending on your schema). So this
Exception exists to allow you handling this problem beforehand. There is
no default action for this situation.
Bye, Thomas.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]