hello,guys .if in a class ,The transaction has just been committed,next then the Excepction occur in,The previous transaction will still roll-back? as shownbelow, when program walking to int a=1/0,Excepection occured.
i see,thank you so much,I benefited a lot.
No. You should include code (especially database operations) that should either complete successfully or all database changes should be rolled back. The purpose is to prevent inconsistent data changes. For example, imagine that you're deleting an order. You delete the header and when trying to delete lines, an error occur. You want to cancel the whole operation and therefore the delete of the order header must be rolled back. Otherwise you'd end up with lines without an order header. How likely it is that the deletion fails is irrelevant - what you need to consider what forms a single logical operation.
thank you so much i see
See. Simply give a try catch block and in try you can give the transaction. If it is success the execution won't go to catch block and record gets inserted. If some error, then execution comes to catch.
It is not explicitly required to give error code in transaction so that it gives error in a transaction.
As Martin suggested, if error comes with transaction means between ttsbegin commit then only transaction will fail or if exception happens before the transaction. Once it is committed there will be no issue on transaction with this exception.
What I mean is that I only need to include the code that is likely to cause exceptions between ttsbegin and ttscommit, and nothing else
Sorrt, I don't understand what you're saying. Please elaborate.
In my understanding, I would only put database operations between ttsbegin and ttscommit
i know,But not all exceptions are ready to be caught, even if the server goes down just after the transaction has been committed
I don't know what is so difficult on it. An exception aborts a transaction only if it's thrown in a transaction. Your 'throw' statement isn't in a transaction and therefore there is no transaction it could influence.
If update() (line 5) threw an exception, the transaction would be rolled back, because update() *is* called inside a transaction.
What you mean is that a transaction must cover any code that might have an exception?
[quote user="Tracy wang"]hello,guys .if in a class ,The transaction has just been committed,next then the Excepction occur in,The previous transaction will still roll-back? as shownbelow, when program walking to int a=1/0,Excepection occured.
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156