trying to get some info abt transaction from help file. quite confusing. Please give some advise for my case:
I need to save two db entries, and both must be saved successfully, either one fail, all shall be aborted. here is my code, please let me know whether i put it right:
try
{
pbroker.starttransaction();
obj1.save();
obj2.save();
pbroker.commit();
}
catch
{
pbroker.rollback();
}
and how to use the "isolationLevel" parameter here?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dim p as AToMSFramework.CPersistenceBroker = New AToMSFramework.CPersistenceBroker
p = AToMSFramework.getPersistenceBrokerInstance()
p.startTransaction(IsolationLevel.RepeatableRead) 'Inicia transaccion
obj.save()
obj1.save()
.....
p.commit()
....
p.rollBack()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Victor's answer is correct. Be aware that if you are just saving, you don't really need to use the isolation level - you'd only use that if you are doing pessimistic locking.
To save using optimistic locking only; your original code is correct.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
trying to get some info abt transaction from help file. quite confusing. Please give some advise for my case:
I need to save two db entries, and both must be saved successfully, either one fail, all shall be aborted. here is my code, please let me know whether i put it right:
try
{
pbroker.starttransaction();
obj1.save();
obj2.save();
pbroker.commit();
}
catch
{
pbroker.rollback();
}
and how to use the "isolationLevel" parameter here?
Thanks!
Hi.
Use:
Dim p as AToMSFramework.CPersistenceBroker = New AToMSFramework.CPersistenceBroker
p = AToMSFramework.getPersistenceBrokerInstance()
p.startTransaction(IsolationLevel.RepeatableRead) 'Inicia transaccion
obj.save()
obj1.save()
.....
p.commit()
....
p.rollBack()
Hi Timothy,
Victor's answer is correct. Be aware that if you are just saving, you don't really need to use the isolation level - you'd only use that if you are doing pessimistic locking.
To save using optimistic locking only; your original code is correct.