Have a transaction in a grails Service class on which a rollback flag is set:
TransactionAspectSupport
.currentTransactionInfo()
.transactionStatus
.setRollbackOnly()
what happens is that when we return to the Controller an exception:
org.springframework.transaction.UnexpectedRollbackException
which we have to catch in the Controller (but not in any of the Service classes). This code is being refactored from the previous solution where all the logic happened direct in the Controller. Any advise on what happens that trips this exception to be thrown when the method returns, given that:
static transactional = true
has been set on all the classes. Guessing theres some subtle Controller verses Service magic happening - does anyone know about this? For now开发者_开发技巧 just catching the exception as a workaround, but this loses the TransactionStatus object that otherwise would have been returned.
Any thoughts much appreciated
Transaction management in Grails is pretty ugly (for me). So i'm proffering Spring declarative transactions: Chapter 9. Transaction management They works perfectly in grails services.
Returning back to setRollbackOnly(). This method is not simple... While you have set RollBack=true in your inner transaction you have triggered to rollback your outer transaction to sou you are getting exception.
I've similar problem some time ago - here is useful info to find best solution suiting for you:
- AbstractPlatformTransactionManager.setGlobalRollbackOnParticipationFailure(false)
- Grails - Declarative Transactions
- Declarative transactions don't works in 1.3.x ?
精彩评论