title: JPA update query: cache not properly invalidated
body: <p>Why doesn't it work:</p>
  
  <pre><code>@Test
  public void test() {
      EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-pu");
      EntityManager entityManager = entityManagerFactory.createEntityManager();
      String id = "id";
      long value = 1234L;
  
      entityManager.getTransaction().begin();
  
      FancyEntity fancyEntity = new FancyEntity(id);
      entityManager.persist(fancyEntity);
      int updateCount = entityManager.createQuery("update FancyEntity item set item.value = ?2 where item.id = ?1").setParameter(1, id).setParameter(2, value).executeUpdate();
      assertEquals(1, updateCount);
  
      FancyEntity checkResult = entityManager.find(FancyEntity.class, id);
      assertEquals(1234L, checkResult.getValue()); // &lt;- this assert fails
  
      entityManager.getTransaction().commit();
  }
  </code></pre>
  
  <p>with</p>
  
  <pre><code>@Entity
  public class FancyEntity {
      @Id
      private String id;
      @Column
      private long value;
      public FancyEntity(String id) {
          this.id = id;
          this.value = 0;
      }
      public FancyEntity() {
      }
      public long getValue() {
          return value;
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;persistence-unit name="test-pu"
                    transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;class&gt;com.fancypackage.FancyEntity&lt;/class&gt;
  
      &lt;properties&gt;
          &lt;property name="eclipselink.logging.level" value="SEVERE"/&gt;
          &lt;property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /&gt;
          &lt;property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem;sql.enforce_strict_size=true;hsqldb.tx=mvcc" /&gt;
          &lt;property name="eclipselink.ddl-generation" value="drop-and-create-tables" /&gt;
          &lt;property name="eclipselink.ddl-generation.output-mode" value="database" /&gt;
          &lt;property name="eclipselink.logging.level.sql" value="FINE"/&gt;
          &lt;property name="eclipselink.logging.parameters" value="true"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>Result is </p>
  
  <pre><code>java.lang.AssertionError: 
  Expected :1234
  Actual   :0
  </code></pre>
  
  <p>It seems there is some cache that is not invalidated by the update query. <code>checkResult</code> and <code>fancyEntity</code> are the same object. Forcing the refresh using <code>entityManager.refresh(checkResult)</code>. The weirdest thing is that a <code>select</code> is issued for retrieving <code>checkResult</code> (seen in the eclipselink log), still its result is not taken into account. Same behavior using MySQL rather than HSQL.</p>
  
  <p>Any hint on what could be wrong ?</p>