1 Reply Latest reply on Mar 8, 2012 7:51 AM by serkan

    How to avoid record updated automatically when records are retrieved

    simonc2009

      Dear All,

       

      I have a function written in richfaces 3.2.2 and backend is Seam 2.

      User will click a "retrieve" button of that function and a list of record is being displayed from database.

      However I found records are being updated automatically if the retrieve method contains "set" methods as below:

       

      public void getHotels() {

       

              hotels = em.createQuery("select h from Hotel h")

              .getResultList();

       

              for (Hotel h : hotels) {

                  if (h.getId()-1==0) {

                      System.out.println("xxxxxxxxxx");

                      System.out.println(h.getAddress());

                      h.setAddress("1");   <------------------------- entity is updated

                  }

              }

      }

       

      I want to disable the above automatic entity update; I want to save records only when used click "save" button.

       

      Please help and thanks

        • 1. Re: How to avoid record updated automatically when records are retrieved
          serkan

          Hmmm...a very nasty situation.

           

          If the value you set is never gonna be saved into the db then try to solve it in your front-end with EL by doing something like this:

           

          <span>#{hotel.id gt 0 ? hotel.id : -1}</span>

           

          Otherwise use manual flushing on your method, which prevents auto-commits to the db. Note that your class must be in the conversation scope to use manual-flushing !

          And check the Seam manual about this.

           

          Good luck.