4 Replies Latest reply on May 1, 2007 12:10 PM by knaas

    two transactions, one entityManager

      We have an application where every 5 minutes an a4j:poll queries to see if there are any user alerts to display. If there is an alert, the user is presented with a modal dialog. They then click an OK button on the dialog which causes the Alert to save to the database with the acknowledgment time.

      This alert dialog can be displayed on any screen in the application, but the alert acknowledgment action should not participate in those screen's transactions.

      It works great in every scenario except for the following: The user is on an edit screen and is making changes. A new alert modal dialog is displayed and the user clicks OK. The alert acknowledgment time is saved, but so are the user's changes on the edit screen. This is not good.

      The alert action is a Stateful EJB.

      I have tried numerous ways to get this to occur how I want using @TransactionAttribute.NOT_SUPPORTED, REQUIRES_NEW, but I just cannot get it to work.

      When the form posts and the acknowledge alert action is called, is it possible that the form values for the edit screen are also being applied to this new "nested" transaction or is the transaction demarcation not really occurring like I think it is?

        • 1. Re: two transactions, one entityManager

          I also failed to mention that I have tried MANUAL and AUTO flush mode with no change in behavior.

          I have also tried manually creating a nested conversation in the action and then popping it at the end. No change in behavior.

          • 2. Re: two transactions, one entityManager
            vralev

            I think this will work if you use the factory to create separate EMs:

            @PersistenceUnit javax.persistence.EntityManagerFactory emf;


            then:

            EntityManager em1 = emf.createEntityManager();
            ...


            • 3. Re: two transactions, one entityManager
              pmuir

              Or of course you could create two Seam entity managers in components.xml. You'll need to make sure you load the alerts using the alternative entity manager.

              • 4. Re: two transactions, one entityManager

                Thanks petemuir and vladimir.

                The approach that we decide to take was to connect the modal dialog to a @WebRemote. This isolates the alert transaction to a separate conversation. It is probably better this way since I don't have to worry about JSF restoring the view each time we ask for more alerts from the server. Thus, as expected, performance is considerably faster.