Please tell me whether it is safe and recommended to catch other exceptions within the SRC and @transaction methods ? When programmatic transaction management is used, then I can just catch the exception and do whatever I want, but I do not know that by catching these exceptions, the transaction does not break the AOP system, which is otherwise The rollback will trigger ... if I do it in declarative manner.
I think there are behind the scenes, which generate a logical transaction with a different connection to the AOP Advice @ Transaction methods. And they need to catch the exception that "I want to catch up" and want to roll back the transaction.
You can mark transaction programs as rollback only by using this code
TransactionAspectSupport.currentTransactionStatus (). SetRollbackOnly ();
See it in
But it has not been recommended because you are adding your code to the spring structure tightly.
Perhaps, if you do this in more than one place, then you should introduce a helpful method, such as TransactionUtils.rollbackCurrentTransaction ()
. In this way, if you decide to change your behavioral point of view (or God does not, go away from spring), then you have to change only one method.
Comments
Post a Comment