Jul 11th, 2011, 06:07 PM
UnexpectedRollbackException is somewhat unexpected to me
My Testcase is a outer and an inner service, advised by spring using jta and atomikos. The outer service starts the transaction, the inner service is running in the same transaction.
In the inner service i set programmatically TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly(). So the rollbackOnly attribute of the AbstractTransactionStatus from inner service turns true.
As it stands, the outer service !must! take notice of the rollback through the isGlobalRollbackOnly of DefaultTransactionStatus and TransactionAspectSupport.currentTransactionStatus( ).setRollbackOnly() itself - else the UnexpectedRollbackException is thrown.
Is this reaction by isGlobalRollbackOnly and setting setRollbackOnly the right "countermeasure"?
I read that this UnexpectedRollbackException is a designed and default behavior. Outside of spring using transactions, i must design my service to either take action on a rollbackonly or not. I appreciate that you designed that carefully, maybe for programmers that are not aware of that situation. But I suggest to make that behavior configurable. If a client should be notified by UnexpectedRollbackException, i can opt for that.
1) With that designed spring behavior i have no decision in that, must do exactly that coding.
2) Also the some service may not always be the most outest - hence, beginning and ending the transaction. With that designed spring behavior i have to put that code in every service.
3) I can make the client aware of that fact by returning some adequate response. If its expected business behavior, this should be the default, not the UnexpectedRollbackException.
In the meantime - to get my favorite behavior - i have a LocalRollbackOnlyHelperAdvice, which runs by ordering before the TransactionAspectSupport and sets the local rollback.
P.S. btw, why are there two different instances of DefaultTransactionStatus, one per service, within the same transaction? If there was on instance only, setting rollbackonly on the inner service would be "recognized" by the outerservice.
Tags for this Thread