db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raphael.x.man...@gsk.com
Subject Re: Réf. : Torque is inserting, not updating
Date Wed, 23 Mar 2005 09:28:23 GMT
Torque's save() method is relying on the internal 'new' and 'modified'
flags to determine whether to insert or update.

In the one case you constructed a new object that just happened to have
similar values (including PK) to an existing object. However its internal
flags were set to new, not modified. The results is an insert.

In the other case, you took an exisitng object and modified it to try to
create a new object. However  its internal flags are not new, modified. the
result is an update.

I have had the same problem when serialising objects and sending them over
the network. You must either ensure that the 'new' and 'modified' flags are
set properly or else call doInsert() or doUpdate() explicitly and not save
(). Save() looks at the flags; doInsert() and doUpdate() do not.

Doing a duplciate insert on an existing object under Oracle gets you the
mysterious 'SET TRANSACTION must be first in transaction' error message.
Totally unrelated to the real error and very confusing.




|---------+---------------------------->
|         |           bernard.noel@vall|
|         |           ourec.fr         |
|         |                            |
|         |                            |
|         |           23-Mar-2005 08:42|
|         |           Please respond to|
|         |           "Apache Torque   |
|         |           Users List"      |
|         |           <torque-user@db.a|
|         |           pache.org>       |
|         |                            |
|---------+---------------------------->
  >-------------------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                                  |
  |                                                                                      
                                  |
  |                                                                                      
                                  |
  |       To:      "Apache Torque Users List" <torque-user@db.apache.org>          
                                        |
  |                                                                                      
                                  |
  |       cc:                                                                            
                                  |
  |       Subject: Réf. : Torque is inserting, not updating                             
                                   |
  >-------------------------------------------------------------------------------------------------------------------------|




Hi,

An other way to do your update :

ObjectPeer.doUpdate(yourObject) instead of yourObject.save()

You can also load the object first

yourObject = ObjectPeer.retrieveByPK(id);
...
yourObject.save() ==> it will update and not insert

Hope this can help,

Bernard




                    "Will Keeling"

                    <w.keeling@tisc        Pour :
<torque-user@db.apache.org>
                    ali.co.uk>             cc :

                                           Objet :      Torque is
inserting, not updating
                    23/03/2005

                    09:28

                    Veuillez

                    répondre à

                    "Apache Torque

                    Users List"







Hi,

I'm new to Torque and I'm having a slight problem where I'm calling save()
on a Torque object and it's doing an insert when I'm expecting it to do an
update.

I'm creating a new object and setting a number of it's fields including
it's
primary key field - an 'id' field which is of type 'int'. I would have
expected Torque to realise that with the primary key field set, the object
it's not considered to be new and therefore it should attempt an update.
But
it always does an insert.

The way round this I've found is to call setNew(false) on my object before
calling save() to force Torque to do the update.

Is calling setNew(false) the right way to be doing this (I wouldn't have
thought so)?

I'd be grateful for any advice!

Many thanks in advance,

Will



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-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








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


Mime
View raw message