title: Editing an EJB entity
body: <p>I've got a method in ejb part that has to increment a simple integer value of an entity and persist the changes into db.
  I can't get it work, as it prints always the same value!</p>
  
  <p>Here's the code :</p>
  
  <pre><code>public void incrementDownloads(Dispensa dispensa) {
      int dl = dispensa.getDownloads();
      System.out.println(dispensa.getTitolo() + " had " + dl + " downloads");
      dispensa.setDownloads(dl++);
      dispensaFacade.edit(dispensa);        
      dispensa = dispensaFacade.refresh(dispensa);
      System.out.println("now it has " + dispensa.getNumDownloads());
  }
  </code></pre>
  
  <p>where <code>dispensaFacade</code> used methods are the one from the autogenerated <code>AbstractFacade</code>:</p>
  
  <pre><code>public void edit(T entity) {
      getEntityManager().merge(entity);
  }
  
  public T refresh(T entity){
      T res = getEntityManager().merge(entity);
      getEntityManager().refresh(res);
      return res;
  }
  </code></pre>
  
  <p>My code prints out :</p>
  
  <blockquote>
    <p>Title 1 had 0 downloads</p>
    
    <p>now it has 0</p>
  </blockquote>
  
  <p>which is clearly wrong!</p>
  
  <p>Where's the mistake?</p>