5 Replies Latest reply on Apr 11, 2010 8:31 AM by kapitanpetko

    Capturing a rollback or commit by Seam

    rnicholson10

      Firstly, we are using Seam global transactions with hibernate as the persistence provider.


      Depending on whether the global transaction is committed or rolled back we need to be able to intercept this occurrence. The reason for this is that we send a completion message to another server when certain operations are performed. What we have found is that if the sending of the message is the last thing to be performed in the action that the transaction with the database can still fail and we have already sent a message saying it completed successfully.


      What we really need is an event fired on the action that indicates whether or not the transaction was committed or rolled back so we know whether or not to send the message.


      It should be noted that the sending of the message is not transactional not does it have any interaction with the persistence context.


      I'm hoping that someone can help with this as I'm having no luck luck figuring it out on my own!


      Cheers,


      Ross

        • 1. Re: Capturing a rollback or commit by Seam
          gaborj

          Hi,


          Have you tried observing those nice build-in events? i.e. :

          org.jboss.seam.afterTransactionSuccess.<entitySimpleName>

          You can use also
          @Asynchronous

          methods for the observer methods which will not block the caller thread...


          hope that helps...

          • 2. Re: Capturing a rollback or commit by Seam
            rnicholson10

            I'm looking for more of a global observer for the global transacttion demarcated by the action. Seeing when each entity commits really does not help me as I'm persisting over 10,000 entities in a single transaction and these entities consist of over 50 different types of entity.


            So maybe I should rephrase my question. If I'm persisting many different types of entity in a single transaction how do I capture when this transaction commits of rolls back?

            • 3. Re: Capturing a rollback or commit by Seam
              kapitanpetko

              Global transactions are implemented as a JSF listener (SeamPhaseListener). If all else fails, you can extend/override it and make it do what you want. That said, you can probably observe org.jboss.seam.afterTransactionCompletion to get notified when a transaction commits. It has a boolean parameter to tell you if it completed or failed.


              HTH

              • 4. Re: Capturing a rollback or commit by Seam
                rnicholson10

                Nikolay Elenkov wrote on Apr 09, 2010 03:51:


                Global transactions are implemented as a JSF listener (SeamPhaseListener). If all else fails, you can extend/override it and make it do what you want. That said, you can probably observe org.jboss.seam.afterTransactionCompletion to get notified when a transaction commits. It has a boolean parameter to tell you if it completed or failed.

                HTH



                Brilliant, the observer for afterTransactionCompletion was exactly what we needed. Strangly it seems to be undocumented! Is it guaranteed that this event will always fire, i.e. can we treat it like finally block of a try/catch?

                • 5. Re: Capturing a rollback or commit by Seam
                  kapitanpetko

                  I certainly can't guarantee it :) Look at the code of SeamPhaseListener for details, but it should fire every time. It does seem it's not in the manual. I think it used to be in the 2.0.x version, but not a 100% sure. Or maybe it was in 'Seam in Action'.