db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <florianf...@compuserve.de>
Subject Re: need help
Date Thu, 17 Jun 2004 06:46:04 GMT
Hi William!
The problem is that you're updating the primary key.
You call something like emailObj.setEmail("xyz@xyz.com"). The old 
EMail-Address is overwritten and not longer present. If you now call 
emailObj.save() a update will be performed due to emailObj.isNew() 
returns false. Torque will generate a SQL statement like "UPDATE EMAIL 
SET ... WHERE EMAIL.EMAIL = "xyz@xyz.com". This update will fail 
because no such row will be found in your database. 
You will have to do a doUpdate yourself.

Here's an example for solving your problem:
Criteria value = new Criteria();
value.add(EMailPeer.EMAIL, "xyz@xyz.com");

Criteria selection = new Criteria();
selection.add(EMailPeer.EMAIL, currentEMail.getEMail());

EMailPeer.doUpdate(selection, value);

Hope this helps.

F. Fray


Be aware of changing a primary key! Not only referential integrity in 
your database must be guaranteed by you application, but the identity 
of your eMail object will change also.
You should take a minute to think about choosing an eMail-address as 
primary key of a table. In most cases a numeric identifier will be the 
first choice. 

----- Originalnachricht -----
Von: "??(William)" <williamx@infoacer.com>
Datum: Donnerstag, 17. Juni 2004 1:58 am
Betreff: need help

> Hi All,
> I need help. 
> I set email as a table' primary key,  can I modify this field 
> through Torque save() method.  
> looks it don't work,  when I first retrive obj from old email 
> primary key, then I change email field using setEmail() method, 
> at last, obj.save(), but it doesn't replace email field with new 
> data. 
> Could anyone tell me what the problem is ?
> William
> -------------------------------------------------------------------
> --
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message