db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <Fisc...@seitenbau.net>
Subject RE: ComboKey composite primary key: modifying PK fields
Date Wed, 11 Aug 2004 16:55:57 GMT


I do not think this behaviour is as weird as it seems at fisrt thought. A
primary key is there to identify an object uniquely, so if you change the
primary key, you have a new object. Therefore, the update with the current
values from the pk is ok for me.
Usually this kind of problem pops up if your primary key also has a meaning
in the real world. I have found it extremely helpful to use only primary
keys which have no meaning in the real world except to identify the object
uniquely; but this might not make sense in under all circumstances.

Suggestion how to change a primary key:
start a transaction
load the object
call the peer class to delete the object by pk but keep a reference to the
object in memory
modify the primary key by the object's getters and setters
call the setModified() and setNew() methods of your object both with
argument true
save the object (Torque will use a insert to do this because it thinks the
object is new)
commit the transaction.

   Hope that helps,


Marius Siegas <marius@elinara.ktu.lt> schrieb am 11.08.2004 17:51:44:

> Hi,
>    I tried to modify my fields which are part of primary key and save
>    object and it doesn't work. After some investigations i found out
>    that Torque builds the WHERE clause from current values of the PK
>    fields. Don't you think this behavior is ill? I try to modify one
>    object and it turns out i will update another... On the other hand,
>    what if i want to change the value of my primary key? Is it so
>    uncommon?.. Torque could save objects PK when loading and then use
>    it for saving object, why not?
> --
> Marius
> ---------------------------------------------------------------------
> 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-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message