You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Bonnie MacKellar <BM...@mobius.com> on 2003/07/21 23:14:58 UTC

updates and optimistic locking

I must be doing something really wrong, because when I write code that
I THINK should generate an update statement, an insert statement is
generated instead. I am trying to use optimistic locking. I recalled
that there was a bug that involved optimistic locking and updates, so
I downloaded and built the most recent code from the CVS, and
still the wrong queries are generated.

This is the code that I think should cause an update :

           broker = PersistenceBrokerFactory.defaultPersistenceBroker();
           
           broker.beginTransaction();
           AccountInterface acc = retrieveAccountByNumber("1234");
        
           acc.setTelephoneNumber("555-5555");
           broker.store(acc);
           broker.commitTransaction();

This is what is actually generated (from spy.log)

1058821254048|201|27|statement|SELECT
accountID,isDisconnected,serviceType,deleteTag,customerID,deleteTagSetDate,t
elephoneNumber,accountNumber,rowVersion,billingCycle FROM Account WHERE
accountID = ? |SELECT
accountID,isDisconnected,serviceType,deleteTag,customerID,deleteTagSetDate,t
elephoneNumber,accountNumber,rowVersion,billingCycle FROM Account WHERE
accountID = '5' 
1058821254658|781|21|statement|INSERT INTO Account
(accountID,rowVersion,accountNumber,deleteTag,deleteTagSetDate,isDisconnecte
d,telephoneNumber,serviceType,billingCycle,customerID) VALUES
(?,?,?,?,?,?,?,?,?,?) |INSERT INTO Account
(accountID,rowVersion,accountNumber,deleteTag,deleteTagSetDate,isDisconnecte
d,telephoneNumber,serviceType,billingCycle,customerID) VALUES
('1','0','1234','false','','','555-5555','','','0') 
1058821254678|0|21|rollback||

Since the record alreayd exists, an exception is thrown and the transaction
rolls back.

Is my code completely wrong? I thought I had understood the tutorial.

Thanks,
Bonnie MacKellar
software engineer
Mobius Management Systems, Inc.
bmackell@mobius.com


Re: updates and optimistic locking

Posted by Thomas Mahler <th...@web.de>.
Hi Bonnie,

Your code looks correct. But I'm in doubt about retrieveAccountByNumber().
What happens in this method?

What's really strange with the generated SQL that OJB tries to check
if there is an existing account with ID=5

But the insert is done with the value ID=1 !

There seems to be some manipulation of the id attribute in the meantime.
That's really strange!
Please provide the class-descriptor for AccountInterface and the 
implementation class.


cheers,
Thomas

Bonnie MacKellar wrote:
> I must be doing something really wrong, because when I write code that
> I THINK should generate an update statement, an insert statement is
> generated instead. I am trying to use optimistic locking. I recalled
> that there was a bug that involved optimistic locking and updates, so
> I downloaded and built the most recent code from the CVS, and
> still the wrong queries are generated.
> 
> This is the code that I think should cause an update :
> 
>            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
>            
>            broker.beginTransaction();
>            AccountInterface acc = retrieveAccountByNumber("1234");
>         
>            acc.setTelephoneNumber("555-5555");
>            broker.store(acc);
>            broker.commitTransaction();
> 
> This is what is actually generated (from spy.log)
> 
> 1058821254048|201|27|statement|SELECT
> accountID,isDisconnected,serviceType,deleteTag,customerID,deleteTagSetDate,t
> elephoneNumber,accountNumber,rowVersion,billingCycle FROM Account WHERE
> accountID = ? |SELECT
> accountID,isDisconnected,serviceType,deleteTag,customerID,deleteTagSetDate,t
> elephoneNumber,accountNumber,rowVersion,billingCycle FROM Account WHERE
> accountID = '5' 
> 1058821254658|781|21|statement|INSERT INTO Account
> (accountID,rowVersion,accountNumber,deleteTag,deleteTagSetDate,isDisconnecte
> d,telephoneNumber,serviceType,billingCycle,customerID) VALUES
> (?,?,?,?,?,?,?,?,?,?) |INSERT INTO Account
> (accountID,rowVersion,accountNumber,deleteTag,deleteTagSetDate,isDisconnecte
> d,telephoneNumber,serviceType,billingCycle,customerID) VALUES
> ('1','0','1234','false','','','555-5555','','','0') 
> 1058821254678|0|21|rollback||
> 
> Since the record alreayd exists, an exception is thrown and the transaction
> rolls back.
> 
> Is my code completely wrong? I thought I had understood the tutorial.
> 
> Thanks,
> Bonnie MacKellar
> software engineer
> Mobius Management Systems, Inc.
> bmackell@mobius.com
> 
> 


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