You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Mooslechner Martin <ma...@siemens.at> on 2001/11/07 16:51:04 UTC
Persistent update of PK value(s) with Peers
Hi,
Using Peers, I try to update the CategoryID (PK) value in one Category from
1 to 314. (yes, this is a classic category+item example ;)
As this very Category also has a associated collection of Items in another
table the Category.setCategoryId("314") method also executes these lines of
code (autogenerated by torque):
// update associated Items
if (collItems != null )
{
for (int i=0; i<collItems.size(); i++)
{
((Id)collItems.get(i))
.setCategoryId(v);
}
}
thereby updating all Items with the new Category number 314
After these changes have applied to the objects I also want to make them
persistant.
So I call
myInstanceOfCategory.save()
(which recursively calls the save() methods of each Item)
However the changes are not written in the database:
The doUpdate() in BaseCategoryPeer uses (at last) the BasePeer.doUpdate(
Criteria selectCriteria, Criteria criteria ) signature:
/**
* Method to do updates.
*
* @param Criteria object containing data that is used to create the
UPDATE statement.
*/
public static void doUpdate(Criteria criteria) throws Exception
{
Criteria selectCriteria = new
Criteria(mapBuilder.getDatabaseMap().getName(), 1);
selectCriteria.put( CATEGORYID,
criteria.remove(CATEGORYID) );
BasePeer.doUpdate( selectCriteria, criteria );
}
but the selectCriteria object gets its criterion from the already changed
Category instance (with CategoryId=314)!
So I figure, since there is no row with CategoryId=314 yet in the DB,
nothing is updated!
What must I do to update my Category and its associated Items in the DB?
Do I have to write my own doUpdate in CategoryPeer?
Or is there something generated by Torque what I could use?
(If there is nothing that can handle this, wouldn't the following code have
no purpose?)
// update associated Items
if (collItems != null )
{
for (int i=0; i<collItems.size(); i++)
{
((Id)collItems.get(i))
.setCategoryId(v);
}
}
Thank you for any hints,
Martin Mooslechner
martin.mooslechner@siemens.at
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>