4 Replies Latest reply on Mar 10, 2010 4:32 PM by nimo stephan

    manual flush and transactions

    nimo stephan Master

      I use a Conversation Bean with manual flushing - what does it mean to my transactions?


      Does each flush has its ownl Transaction?


      public void()
      {


      // Transaction 1
      ...
      entityManager.flush();



      // here begins a new Transaction ? Transaction 2
      ...
      entityManager.flush();


      }

        • 1. Re: manual flush and transactions
          Arbi Sookazian Master

          With Hibernate manual flush (enabled for a LRC via @Begin(flushMode=FlushModeType.MANUAL)), you typically manually flush the persistence context at the end of a LRC (i.e. synchronize dirty/new/removed objects with db tables).  So during a JTA tx, the tx does not commit until the end of the business interface method (assuming that a tx is required, which is the default for EJB session beans) as long as no RuntimeException is thrown.


          So no, each flush() in the same business interface method happens during the span of the same tx.


          Read Seam ref doc, Seam in Action or JPwH books for more details.

          • 2. Re: manual flush and transactions
            nimo stephan Master

            As figured out in http://seamframework.org/Community/DoesSeamsEntityManagerDisturbsTransactionAttributesInEJB.


            I have tested the seams manual flush and used that before a lot without problems.


            Now, I have a long running method which calles other methods and the flush is only called at the end of this long running method.


            But however, I can see in my log, that the flush is called randomly - even I do not trigger it by myself. So whats going on?


            I definitly use seams manual flush-option and can see that the flush is for example called before using a createNamedQuery to get results from the database. How can I really enforce that flush is only called when I call entityManager.flush() ?


            Does Seam automatically calls flush if memory is close? Or are their any limitations when manualFlush does not work??


            So you say:



            So no, each flush() in the same business interface method happens during the span of the same tx.

            Does it mean, that when I see in my log that entities are updated or inserted while method excecution, these flushes ALL lie within ONE Transaction?


            I cannot believe it, as I have for example a INSERT (T1) and then some logic and after that again a UPDATE (T2), but all these are called within a method which calls other methods. So my log tells me that a Insert is happen at date 11:14:20,521 a and a update is happen at date 11:16:20,521. So T1 and T2 are not the same Transactions! Am I right?

            • 3. Re: manual flush and transactions
              nimo stephan Master

              As you see the code in


              I use SMPC http://seamframework.org/Community/DoesSeamsEntityManagerDisturbsTransactionAttributesInEJB.



              @In (create=true) private EntityManager entityManager;



              in a stateless session bean.


              You see, I do not use this entityManager in my Conversation-Bean, but in my stateless session bean.

              • 4. Re: manual flush and transactions
                nimo stephan Master

                okay, solved.


                Arbi, you are right:


                flush()


                flush()


                comit();



                2 flushes lies within the same transaction.




                greetings.