更新数据库时我应该更喜欢什么?两种方法的优缺点是什么?我什么时候应该使用其中一种?
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();
}