public Boolean deleteStaff(StaffEntity staff) { Session session = SessionFactoryProvider.getSessionFactory().openSession(); Transaction dbTransaction = null; try { dbTransaction = session.beginTransaction(); StaffEntity staffToDelete = (StaffEntity) session.get(StaffEntity.class, staff.getStaffId()); session.delete(staffToDelete); dbTransaction.commit(); } catch (HibernateException error) { if (dbTransaction != null) dbTransaction.rollback(); error.printStackTrace(); return false; } finally { session.close(); } return true; }
public void updateStaff(StaffEntity staff) { Session session = SessionFactoryProvider.getSessionFactory().openSession(); Transaction dbTransaction = null; try { dbTransaction = session.beginTransaction(); StaffEntity staffUpdate = (StaffEntity) session.get(StaffEntity.class, staff.getStaffId()); log.info("Updating: " + staffUpdate.toString()); staffUpdate.setFireNumber(staff.getFireNumber()); staffUpdate.setFirstName(staff.getFirstName()); staffUpdate.setLastName(staff.getLastName()); staffUpdate.setRank(staff.getRank()); staffUpdate.setHireDate(staff.getHireDate()); staffUpdate.setTermDate(staff.getTermDate()); staffUpdate.setDepartmentId(staff.getDepartmentId()); session.update(staffUpdate); dbTransaction.commit(); } catch (HibernateException error) { if (dbTransaction != null) dbTransaction.rollback(); error.printStackTrace(); } finally { session.close(); } }