Entitymanager.flush() VS EntityManager.getTransaction().commit - 我应该选择什么?
2022-08-31 20:36:17
更新数据库时,我应该选择什么?这两种方法的优缺点是什么,我什么时候应该使用一种或另一种?
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();
}