You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Marius Siegas <ma...@elinara.ktu.lt> on 2004/08/11 17:51:44 UTC

ComboKey composite primary key: modifying PK fields

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


Re: ComboKey composite primary key: modifying PK fields

Posted by Marius Siegas <ma...@elinara.ktu.lt>.
Hi,

   Thanks for your thoughts. Well, ok, maybe this behaviour isn't that
   bad, but i stil think Torque should handle this a bit differently, it
   at least could setNew(true) when i do modify my PKs or do something
   else so i could detect my error more easily... Anyway, i'm happy i
   know about this behaviour now, it could be documented somewhere at
   least.

Thomas Fischer wrote:
> Hi,
> 
> 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,
> 
>      Thomas
> 
> Marius Siegas <ma...@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-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: ComboKey composite primary key: modifying PK fields

Posted by Thomas Fischer <Fi...@seitenbau.net>.



Hi,

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,

     Thomas

Marius Siegas <ma...@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