title: Question about flushing with JPA before a query is called
body: <p>Just a quick question, but is the flush necessary in this code? Note this would be inside of a JPA transaction.</p>
  
  <pre><code>User user = new User();
  em.persist(user);
  
  em.flush;
  
  User aUser = em.find(User.class,user.getId());
  assert(user.equals(aUser));
  </code></pre>
  
  <p>Or is will it work without the flush?</p>
  
  <pre><code>User user = new User();
  em.persist(user);
  
  User aUser = em.find(User.class,user.getId());
  assert(user.equals(aUser));
  </code></pre>
  
  <p>Or same question but a little more involved example:</p>
  
  <pre><code>User user = em.find(User.class,id);
  user.setName("My Name");
  em.merge(user);
  
  em.flush; //Is this line needed?
  
  User aUser = em.createQuery("select u from User where u.name = 'My Name');
  assert(user.equals(aUser));
  </code></pre>