title: JPA Entity not updating correctly
body: <p>I'm using JPA2 with Eclipselink implementation on Glassfish 3.</p>
  
  <p>I have a simple login/logout application.</p>
  
  <p>These are the entity beans an their mappings:</p>
  
  <pre><code>@Entity
  @Table(name = "user_account")
  public class UserAccount implements Serializable{
      @Id
      private Integer id;
      private String email;
      private String password;
      private Integer role;
  
      @OneToOne(fetch=FetchType.EAGER)
      @PrimaryKeyJoinColumn
      private UserDetail userDetail;
  
      // get+set
  }
  
  @Entity
  @Table(name = "user_detail")
  public class UserDetail implements Serializable{
      private static final long serialVersionUID = 1L;
      @Id
      private Integer id;
      @Temporal(TemporalType.DATE)
      private Date birth;
      @Column(name="origin_city")
      private String originCity;
      @Column(name="residence_city")
      private String residenceCity;
      private String description;
  
      @OneToOne(mappedBy="userDetail")
      private UserAccount userAccount;
  }
  </code></pre>
  
  <p>In a <code>UserService</code> class I have a simple CRUD implementation. All the methods work just fine but the problem is that sometimes the Entity Object saved in the Persistance Context / JPA Cache doesn't synchronize with the database information.</p>
  
  <p>As a specific example, when I delete some user details (from the user_detail table) the database entry is deleted but when I read the information again, the returned entity still has the Details information. I'm guessing that this info was kept in the JPA cache and brought back without checking the database first. </p>
  
  <p>Is this the correct behaviour? Is there a way to keep the Cache information synchronized with the database?</p>
  
  <p><strong>LE</strong> : The user Service contains the <code>read(email, password)</code> method which calls a helper method. This helper method contains the CriteriaAPI query which brings all the users with the desired email and password. The Criteria query is tested and works fine.</p>
  
  <pre><code>public UserAccount read(String email, String password){
      List&lt;UserAccount&gt; userList = getUserList(null, email, password, Constants.RESULT_SINGLE);
      return (userList.isEmpty() ? null : userList.get(0));
  }
  
  private List&lt;UserAccount&gt; getUserList(Integer id, String email, String password, String resultType){
      CriteriaBuilder builder = em.getCriteriaBuilder();
      CriteriaQuery&lt;UserAccount&gt; shell = builder.createQuery(UserAccount.class);
      Root&lt;UserAccount&gt; entity = shell.from(UserAccount.class);
      shell.select(entity);
      shell.distinct(true);
      List&lt;Predicate&gt; predicateList = new ArrayList&lt;Predicate&gt;();
      if (id != null){
          ParameterExpression&lt;Integer&gt; param = builder.parameter(Integer.class, "id");
          predicateList.add(builder.equal(entity.get("id"), param));
      }
      if (email != null){
          ParameterExpression&lt;String&gt; param = builder.parameter(String.class, "email");
          predicateList.add(builder.equal(entity.get("email"), param));
      }
      if (password != null){
          ParameterExpression&lt;String&gt; param = builder.parameter(String.class, "password");
          predicateList.add(builder.equal(entity.get("password"), param));
      }
  
      if (predicateList.size() == 1){
          shell.where(predicateList.get(0));
      } else {
          Predicate[] p = new Predicate[predicateList.size()];
          p = predicateList.toArray(p);
          shell.where(builder.and(p));
      }   
      TypedQuery&lt;UserAccount&gt; selectQuery =  em.createQuery(shell);
      if (id != null) selectQuery.setParameter("id", id);
      if (email != null) selectQuery.setParameter("email", email);
      if (password != null) selectQuery.setParameter("password", password);
  
      return selectQuery.getResultList();
  }
  </code></pre>
  
  <p>This is the delete method from the service:</p>
  
  <pre><code>public boolean deleteDetail(Integer userId) {
      boolean ok = true;
      try {
          UserDetail userDetails = em.find(UserDetail.class, userId);
          System.out.println("Trying to delete the detail. The address of the object is: " + userDetails);
          em.remove(userDetails);
          System.out.println("Object deleted. The address is: " + userDetails);
      } catch (Exception e) {
          e.printStackTrace();
          ok = false;
      }
  
      return ok;
  }
  </code></pre>