2 Replies Latest reply on Feb 19, 2011 3:49 AM by Raimund Hölle

    CRUD and multiple persistence contexts

    Raimund Hölle Newbie

      Hello,


      we've a problem with the generated CRUD views / with the EntityHome class.


      On editing an entity, the Edit view starts a new conversation and sets the flushmode to manual:


      <begin-conversation join="true" flush-mode="MANUAL"/>



      This changes the flushmode of all persistence contexts to manual. On persist / update / remove, EntityHome flushes the persistence context - but only that one used for the CRUD entity.


      So all other persistence contexts stay unflushed; on conversation end any updates on that persistence contexts are lost.


      Do anyone have a recommended solution to avoid that?


      Many thanks,
      Raimund


        • 1. Re: CRUD and multiple persistence contexts
          Monkey Den Master

          Right, because you're changing flush-mode to MANUAL for the Conversation, not just the EntityHome you called update/persist/delete on.  Look at EntityHome...all the persistence lifecycle methods do the flushing explicitly. 


          @Transactional
          public String update()
          {
              joinTransaction();
              getEntityManager().flush();
              updatedMessage();
              raiseAfterTransactionSuccessEvent();
              return "updated";
          }
          



          In fact, all they really do is join the transaction and flush.  You'll have to do the same if you're not calling the lifecycle methods on the other EntityHome(s).

          • 2. Re: CRUD and multiple persistence contexts
            Raimund Hölle Newbie

            Thanks for your reply.


            Well, that's not in question. It is clear what is going wrong.


            But it is an inconsistence in the SEAM framework - it switches all entity managers to manual flush mode but explicitly flushes only one at end of application transaction.


            So changes of all other entity managers within the same appliction transaction stays unflushed because the conversation ends after executing the update() / persist() methods.


            In our special case, the entities automatically generate some of their field values using counter tables in a second persistence context (a central database to manage unique numbers for different applications, e. g. SSCC numbers).


            The only solution I found is to overwrite the update() / persist() methods of all home components to flush all contexts not only a single one.


            Not a nice approach.


            Regards, Raimund