Entitymanager.flush () VS EntityManager.getTransaction (). Commit - Co powinienem preferować?

Co powinienem preferować podczas aktualizacji bazy danych? Jakie są zalety i wady jednej i drugiej metody?

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();
}

questionAnswers(5)

yourAnswerToTheQuestion