title: Updating JPA entity with reflection does not work?
body: <p>I have an entity which looks something like this: (I'm coding to the web page so I apologize for any mistakes)</p>
  
  <pre><code>@Entity
  public class Entity {
      @Id
      private Long id;
      private String field;
  
      // Insert getters and setters here...
  }
  </code></pre>
  
  <p>I try to manipulate it using reflection:</p>
  
  <pre><code>Long id = 1;
  
  Entity entity = myDao.getEntity(id);
  
  entity.setField("set directly");
  
  Field[] fields = entity.getClass().getDeclaredFields();
  
  for (Field f : fields) {
      if (f.getName().equals("field")) {
          f.setAccessible(true);
          f.set(entity, "set using reflection");
          f.setAccessible(false);
      }
  }
  
  System.out.println(entity.getField());
  </code></pre>
  
  <p>This program prints "set using reflection". However, in the database the value set using reflection does not get updated:</p>
  
  <pre><code>SELECT * FROM ENTITY WHERE ID = 1
  ID     FIELD
  1      set directly
  </code></pre>
  
  <p>This is strange. I could swear that this used to work - but now it isn't. Is it really so that you cannot manipulate entities using reflection?</p>
  
  <p>I'm using EclipseLink 1.1.1 if that matters.</p>