views:

34

answers:

1

Hi

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

A: 

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:

Olexandr
Thanks for this. However we're run out of time to investigate these alternatives and for now are just catching the exception as the transaction exists the service and enters the controller. Answer definately appreciated however
Alex