7 Replies Latest reply on Feb 19, 2009 9:40 PM by Stuart Douglas

    afterTransactionSuccess not firing

    Jeff Faath Newbie

      Per section 13.3 in the 2.1.1.GA guide near the bottom of the section it claims that I can refresh a query when the underlying entities change by observing the afterTransactionSuccess event.  The example uses a query of Person objects.

      I'm trying to create a similar effect except that I'm trying to store custom system properties in a query in application context.  The configuration is simply this:

      <framework:entity-query name="sysprops" ejbql="from SystemProperty" order="name" scope="application"/>
      <event type="org.jboss.seam.afterTransactionSuccess">
        <action execute="#{sysprops.refresh}" />

      So anytime a SystemProperty is successfully saved (or removed, updated) the global sysprops query gets refreshed.  I've tried a ton of variations and went through a bunch of documentation on transactions, etc.  Does my SystemProperty simply need to be a Home object?  I know I'm missing something really simple, but the documentation seems to imply this should work.

      As a sidebar, this might not even be the best way to this sort of thing as there might be problem with synchonization on the query object.  But right now I just want to know when/how these transaction events get raised.

        • 1. Re: afterTransactionSuccess not firing
          Jeff Faath Newbie

          Can someone please tell me under what conditions the afterTransactionSuccess event is supposed to fire?  The document says:

          org.jboss.seam.afterTransactionSuccess — called when a transaction succeeds in the Seam Application Framework

          Yet when I run a simple action that takes the injected EntityManager and persists an entity, no event is fired.  My transactions are configured like this:

          <transaction:entity-transaction entity-manager="#{entityManager}"/>

          Does the entity have to be a Seam component?  I would think the transaction should be noticed through the Seam-managed EntityManager.

          • 2. Re: afterTransactionSuccess not firing
            Stefano Travelli Newbie

            It is fired when a transaction succeds in the Seam Application Framework.

            Actually, this means that it's fired when you call entityHome.persist() or entityHome.update().

            If you persist your entity by yourself, inside a custom DAO object, calling  entityManager.persist(), issuing an entityManager.flush() during a long running conversation o whatever, that event will not be fired.

            Looking at the source code of org.jboss.seam.framework.Home may help. Find all usages of raiseAfterTransactionSuccessEvent() method with a smart IDE to get the logic behind this feature.

            • 3. Re: afterTransactionSuccess not firing
              Val Sw Expert

              Yes, I have an entity and experimentSavedOrUpdated method is invoked on call to persist or update


              public class ExternalApplicationInvoker
                   public void experimentSavedOrUpdated()
                     executeData(getType(), getHjid());

                   public void generateDataSet()     {     
                        executeData(getType(), getHjid());     

              b) I am invoking this on an event from ui, which calls the above generateDataset observer.
              public String generateDataset(){
                   //Events.instance().raiseAsynchronousEvent(generateDataset, AA, 2);
                   Events.instance().raiseEvent(generateDataset);// can also pass arguments
                   return generateDataset;

              • 4. Re: afterTransactionSuccess not firing
                Jeff Faath Newbie

                Thanks for the reply Stefan.

                I guess I was confused as to what exactly the Seam Application Framework is.

                I figured since the entityManager is being managed as a Seam component and transactions are opened and committed via this entityManager, then these transactions were considered to be under the Seam Application Framework.

                I'll take a look at the source code per your recommendation.

                • 5. Re: afterTransactionSuccess not firing
                  Stuart Douglas Master

                  you may be interested in the event org.jboss.seam.afterTransactionCompletion and org.jboss.seam.beforeTransactionCompletion.

                  These should be raised on every transaction if you are using the application framework or not.

                  • 6. Re: afterTransactionSuccess not firing
                    Jeff Faath Newbie

                    Yep, that sounds like the event I was envisioning (which, fyi, doesn't appear to be in the documentation).

                    However, it doesn't seem to work with my use case from the first post as I am receiving an EntityManager is closed error when trying to refresh the entity query.

                    Looks like I'll have to investigate using the Home object.


                    • 7. Re: afterTransactionSuccess not firing
                      Stuart Douglas Master

                      are you trying to use beforeTransactionCompletion or afterTransactionCompletion?

                      afterTransactionCompletion is called after the transaction is ended and has committed or rolled back, so the entityManager will be closed. I am not sure about beforeTransactionCompletion, the transaction should still be active but the entityManager may be closed. I only found out about them when I was poking around in the transaction code, I did not realize that they were not documented.