title: Entitymanager.flush() VS EntityManager.getTransaction().commit - What should I prefer?
body: <p>What should I prefer when updating the database? What are the pros &amp; cons with either method and when shall I use the one or the other?</p>
  
  <pre><code>public void disemployEmployee(Integer employeeId, Date endDate) {
      Employee employee = (Employee)em.find("Employee", employeeId);
      employee.getPeriod().setEndDate(endDate);
      em.flush();
  }
  
  public void disemployEmployee(Integer employeeId, Date endDate) {
      Employee employee = (Employee)em.find("Employee", employeeId);
      em.getTransaction().begin();
      employee.getPeriod().setEndDate(endDate);
      em.getTransaction().commit();
  }
  </code></pre>