8 Replies Latest reply on Mar 8, 2010 1:33 PM by antibrumm.mfrey0.bluewin.ch

    Seam Updates entities automatically via UpdateTimestampsCache

    infinity2heaven

      I have a SFSB (Conversation scope). The methods are



      
      @In(required=false) @Out(required=false, scope=ScopeType.SESSION)
      private Date selectedTimePeriod;
           
      @In(required=false) @Out(required=false, scope=ScopeType.SESSION)
      private Fof selectedFof;  
      
      @In(required=false) @Out(required=false)
      private FofPerformanceDetail fofPerformanceDetail;
      
      @Begin(join=true)
      public void search()
      
      public void method2()
      
      public void method3()
      
      @FlushMode(value=FlushModeType.COMMIT)        
      public void save()




      Use Case: User clicks on 'search', results are fetched and shown. User changes some values but DOES NOT click on 'save' but changes some search criteria (selectedFof and selectedTimePeriod), clicks on 'search'. Search results are shown again (richfaces rerenders the page). Now, behind the scenes I see that Seam/Hibernate is silently firing an update SQL and updates the fofPerformanceDetail with the client side updates.


      4:58:52,243 DEBUG [UpdateTimestampsCache] Pre-invalidating space [fof_performance_details]
      14:58:52,243 DEBUG [SQL] 
         /* update
              xxx.entity.FofPerformanceDetail */ update
                  fof_performance_details 
      
       .....
      ....
      



      Any idea why this is being called? I have this behavior occurring in all screens now and it's sorta scary!


        • 1. Re: Seam Updates entities automatically via UpdateTimestampsCache
          joaobmonteiro

          Hi,


          If the user changes some values in a managed object, in the end of transaction, the update will occurs. You need to notify Seam that you are responsible for commiting and flushing in that conversation. I think you have to use


          @Begin(join=true,flushMode=FlushModeType.MANUAL)
          
          



          and


          @End public void save(){
          
           em.flush();
          
          }
          
          



          is that work for you?

          • 2. Re: Seam Updates entities automatically via UpdateTimestampsCache
            infinity2heaven

            Thanks for the quick reply!


            That doesn't seem to work, strangely. I don't want to end the conversation on 'Save' as the user can retain on the same page and search/save multiple times. The only way the conversation is ended is by clicking the menu (takes the user away from the screen).


            <s:link view="/manageFofPerformance.xhtml" value="Monthly Data" propagation="none"/>                   
                     
            Do you find anything wrong with this?

            • 3. Re: Seam Updates entities automatically via UpdateTimestampsCache
              joaobmonteiro

              I don´t think it could be a problem. But the question that still remains is that if you change any persistent (managed state in Hibernate) object value it will be flushed to database at transaction end.

              • 4. Re: Seam Updates entities automatically via UpdateTimestampsCache
                infinity2heaven

                True. Considering I'm using a managed persistent context



                <persistence:managed-persistence-context name="entityManager" 
                    persistence-unit-jndi-name="java:/EntityManagerFactories/asrDatasource" auto-create="true"/>


                and an @In injection on my SFSB, rest everything as shown in the above example, how can indicate that the method 'search' and the others should not be treated in transaction boundaries? The Good old way, I used to wire using Spring and add/or add @Transactional on the methods. It seems too simplistic with Seam, but I'd like to understand more of this default configuration.


                Thanks


                    

                • 5. Re: Seam Updates entities automatically via UpdateTimestampsCache
                  infinity2heaven

                  I still haven't figured out why the updates are being fired automatically. I understanding the managed persistent context by Seam and that I should flush it manually, but even after trying the below code, the problem remains the same.


                  @Begin(join=true, flushMode=org.jboss.seam.annotations.FlushModeType.MANUAL) 
                  @Transactional(value=TransactionPropagationType.NEVER)
                  public void search() {
                   ...
                  }



                  To explain further, I only notice this behavior when search is invoked again and not when I navigate away from the page. Clearly, it looks like the problem is coupled with Conversations as I'm beginning a new conversation (with join) on 'search'


                  Pl suggest.

                  • 6. Re: Seam Updates entities automatically via UpdateTimestampsCache
                    infinity2heaven

                    I've been stuck with this issue which has been marked as critical in our system (planning for a UAT release this week). I've spent several hours in the forums, documentation and it's of no use.


                    I'd really appreciate if anyone else has encountered this, or if I could get any further pointers for debugging this issue.


                    Most of the info for the problem, I believe is in this thread, above.


                    Thanks in advance

                    • 7. Re: Seam Updates entities automatically via UpdateTimestampsCache
                      dianad

                      I'm having a very similar problem, have you ever find solution to stop the silent update?
                      Thanks

                      • 8. Re: Seam Updates entities automatically via UpdateTimestampsCache
                        antibrumm.mfrey0.bluewin.ch

                        It's a quite old entry on an issue i think several people have but i'll answer anyway with an approach i've done to avoid it. We had a similar issue because our application is divided into 2 parts on a page.


                        ------------


                        Search (form) 


                        ------------


                        Editor (form) 


                        ------------


                        To make it even more complex we use a rich tabpanel as a multitabeditor...


                        My first approach was to use multiple conversations but i haven't succeeded in getting this to work. (I was not able to push a form into a specific conversation)
                        -- I think this would be the cleanest approach for the problem. Top Conversation on the page level and nested conversation per tab.


                        The problem we have in this configuration is that we edit multiple entities at the same time and if the user clicks the update button in a tab the entity manager will trigger a flush which leads to an update of ALL managed entities that the user changed.




                        So there we are in a general editor problem that i faced also in an Eclipse RCP application. An editor should never work directly on the entity! Else you mess up with the View and Editor concept.
                        - If you change something in the entity in the editor you don't want that the entity is changing somewhere else in your application already!


                        -- The common solution here was that you work always on a clone. This works well also in a Seam application because you work on a detached object. Now, if the user clicks the Update button you have to push the changes down to the real object and let Seam do the rest.
                        This involves quite alot of programming and as a nice sideeffect you loose the Lazy-Loading feature of JPA because you work on a detached object. This needs some more programming..


                        -- My current approach is using a general editor proxy object which encapsulates the entity and takes all changes of the editor. When the user clicks Update i need to call one method and the changes are pushed down to the entity and Seam does the rest.


                        Hope this helps some people.