db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael.Kashamb...@bmwna.com
Subject Torque BaseXXX in Transaction and the isNew() Method Check
Date Sat, 25 Sep 2004 00:08:13 GMT
Hi-

'm having a problem using Torque-generated classes within a transaction.

Let's say I have a table, Person, for which Person.java and BasePerson.java
are generated by Torque.  

When I attempt to save my person instance for the first time, Torque will do
an insert and then set the new attribtue to false on my Person instance.

    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the
database.
            if (isModified())
            {
                if (isNew())
                {
                    PersonPeer.doInsert((Person) this, con);
                    setNew(false);
                }
                else
                {
                    PersonPeer.doUpdate((Person) this, con);
                }
            }

                      alreadyInSave = false;
        }
      }

Now, if I'm running in a transaction and the transaction rolls back due to
some application exception, once the user resolves the problem and attempts
to re-insert the Person instance, it will not be inserted.  Instead, because
isNew() now returns false, Torque will attempt to update the record.
However, this record does not exist in the database since the initial
transaction rolled back.

Has anyone come up with an elegant solution for this problem?

Thanks.

Michael


---------------------------------------------------------------------
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