3 Replies Latest reply on Mar 31, 2009 4:26 AM by Tim

    Why is PreUpdate triggered in this case?

    Emmanuel Rousselle Newbie
      Hello,

      I have a situation where a method annotated with PreUpdate is getting called but in my mind (unless I'm wrong) shouldn't.

      On this page I have a rich:datable element which allows me to browse the results of a query. This element gets its information from an object extending EntityQuery.

      Each datatable row has a link allowing the user to request details about the particular row to be displayed elsewhere on the page ('show me more info about the element I selected' functionality). This is done by setting the Id of an EntityHome instance which will retrieve the proper entity.

      <a:commandLink oncomplete="GEO.fn.showTrack(#{_track.id});" value="Load"
      action="#{trackHome.getInstance}" reRender="thisTrack" >
         <a:actionparam name="trackid" value="#{_track.id}"
                        assignTo="#{trackHome.id}" converter="javax.faces.Long"/>
      </a:commandLink>

      Whenever this link is clicked, for some reason all instances returned by the query are flagged "dirty" and are being updated in the DB (calling PreUpdate).

      My issue is that the database is updated even though none of the entities' properties have actually been modified.

      My questions are:
      - Why is the update being triggered in this case?
      - Am I implementing this scenario the right way or is there a better one?

      Thanks in advance.
        • 1. Re: Why is PreUpdate triggered in this case?
          Emmanuel Rousselle Newbie

          I've made some progress with this issue, but I still have unanswered questions. If somebody could help me that would be appreciated.


          I found the answer to my first question: the JSF update phase appear to be the trigger. I tried to work around this issue, but I only have a partial resolution.


          The workaround is to mark the page as using manual flush mode so that the entity manager only write entity changes to the DB on an explicit call to flush(). That got rid of the entity updates when the user selects an entry in the datatable for display.


          However, a class extending EntityHome (trackHome) is used to provide the data to the web page, with the idea that the user may edit the selected entity. At that point if a call to trackHome.update() is made, I still have my problem: the user-modified entity is updated as well as all the entities returned by the EntityQuery (which the user didn't touch and haven't been modified really).


          I'm starting to wonder if that kind of scenario is too much to handle with Seam classes (EntityHome and EntityQuery) and whether something else should return my list of items in the DB.


          Any advice?

          • 2. Re: Why is PreUpdate triggered in this case?
            Marcio Endo Newbie

            <a:commandLink oncomplete="GEO.fn.showTrack(#{_track.id});" value="Load"
            action="#{trackHome.getInstance}" reRender="thisTrack" >
               <a:actionparam name="trackid" value="#{_track.id}"
                              assignTo="#{trackHome.id}" converter="javax.faces.Long"/>
            </a:commandLink>




            What happens if you use ajaxSingle=true in your a4j:commandLink?

            • 3. Re: Why is PreUpdate triggered in this case?
              Tim Newbie

              It's nothing wrong with your code. Don't try to fix it.


              Actually, the update action is part of earlier modification action. Hibernate flagged those entities as dirty but did not write out changes to DB yet. It's in their caching strategy when the next request to reach DB on the same table. These changes are committed to table, but don't have to read it back because Hibernate got the latest update of these entities already.
              So, that's the reason you see update, but probably won't see select call.