1 Reply Latest reply on Nov 2, 2011 1:56 AM by Martin Frey

    Update Entity on leaving page with a link.

    Hakan Moral Newbie

      "We have cascading fields (like city -> county -> taxoffice) where when a city is selected the county list of the city is filled under city combobox (h:selectonemenu here)
      using a4j:support "onchange" event.

      However when the value of city is changed, to calculate the counties of the city the city value is changed in the entity which causes an update in the database if the user
      navigates to another page before clicking on cancel button: the code doing this is attached. I think we may be making a fundamental mistake using entities directly in the ui.
      but the other options increase the code written and seem as much wrong too.

      here is the view link:


      If anybody came out such a problem, we wish to learn about. Also we have some ideas:
        • 1. Re: Update Entity on leaving page with a link.
          Martin Frey Newbie

          Most likely you have conversations with flushmode auto. This is the standard behavior of seam and it generates exactly the issue that you are describing. There are several ways of dealing with this problem. The simplest one would be that you switch to flushmode manual. Then only when you call flush on the entitymanager your changes will be pushed to the db. This solution is ok if you have full control of whats is changing in the entitymanager. If you edit only single entities in a conversation this will be sufficient.

          Another way would be to detach the entitites, clone them or wrte an adaptor that holds you changes and push the changes only when you want. This approach would be interessting if you have a multieditor for example. With manual flushmode all the changes would be pushed.  Imagine two editors for two entities using the same entitymanager. Now you modify both and click the save button of editor one which will call flush. Both entities are changed and therefore both are commited to the db. If you have for example an adaptor that holds these changes and flush only one adaptor in the save method then only this entity is changed and only one entity is pushed to the db.

          Hope this explains it a little.