db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ludwig Magnusson" <lud...@itcatapult.com>
Subject RE: set(Foreign key) throws exception for no reason?
Date Tue, 16 Mar 2010 18:49:55 GMT
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:tv@apache.org] 
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: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


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


Mime
View raw message