4 Replies Latest reply on Oct 26, 2005 6:28 AM by gavin.king

    Seam managed transactions, rollbacks, and possible annotatio

    rdewell

      I like the idea of Seam managed transactions. I'm using the Seam managed extended persistence context. For the most part I don't even need to think about transactions, which I like.

      However, I'm finding that some of my action methods that do a lot of persistence work have the potential for something to go wrong during the work. Maybe I've built a few objects, and then do something that could cause an exception before I build a few more. If all goes well, everything is of course committed by Seam some time after the action ends.

      However if things don't go well, I can't find a way to rollback my persistence work before returning a failure outcome. What I'd like to do on an exception or problem, no matter how much persistence work I've done previously in the action, is to add a message to JSF and then return an outcome like "failure". This allows the problem to be gracefully handled / communicated in the UI.

      However, as far as I can tell this poses a problem with Seam managed transactions? There's no way I can find to get a hold of the transaction to roll it back before I return "failure". Any ideas on how to drop down and do this, yet still use Seam managed transactions?

      One possibility that I think would be really slick is if there was an action method annotation like: RollbackOn(outcome="failure"). Thus, I still don't have to drop down and get a hold of any transactions, and Seam can still manage the transaction for me. That covers most cases... for others instances and finer grained control, maybe there could be a way to inject a SeamTransaction into my bean?

      Is there a short term solution for rolling back? Any thoughts on the long term suggested additions to Seam regarding this?

      Ryan