2 Replies Latest reply on Apr 2, 2007 10:18 PM by merabi

    setter updates the DB

    merabi

      Hi fellaz.

      my company decided to develop a web app using EJB 3.0 but I'm facing a prob.

      I hav a Entity as follows:

      @Entity
      public class StatusMassAd implements Serializable {
      @Id
      @Column(name="massAd_id")
      private int id;

      private int status;

      public int getId() {
      return id;
      }
      public int getStatus() {
      return status;
      }
      public void setStatus(int status) {
      this.status = status;
      }
      }

      When I use this entity to "setStatus", it updated the DB record after transaction ended.
      The book I have says (or I assume it says) that the EJB will NOT update the DB unless I call the EntityManager's "merge" method.

      I would like to update the DB ONLY if the merge method is called.

      Anyone know how I can stop updating the DB when I use "setters"?

        • 1. Re: setter updates the DB

          You can use entityManager.clear() to detach all (!) entities from the entity manager. Changes to detached entities will only be written after a merge to the db.

          A much cleaner soluction (IMHO) to the problem are Seam's long running transactions.

          Regards


          Felix

          • 2. Re: setter updates the DB
            merabi

            hi fhh.

            thanx for the replay.

            the deadline of the project is too tite that I don think I hav time to learn Seem's new feature.

            I'll try the entityManager.clear() method.

            thanks!