// ADD A EMPLOYEE BANK DETAILS IN tblempbank @Override public int addEmployeeBank(EmployeeBank employeebank) throws HibernateException, ConstraintViolationException { Session session = SessionFactoryUtil.getSessionFactory().openSession(); int status = 0; try { session.beginTransaction(); java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime()); Criteria criteria = session.createCriteria(EmployeeBank.class); criteria.add(Restrictions.eq("organizationId", employeebank.getOrganizationId())); criteria.add( Restrictions.eq("employee", new Employee(employeebank.getEmployee().getEmployeeId()))); criteria.add(Restrictions.eq("bank", new Bank(employeebank.getBank().getBankId()))); if (criteria.list().size() == 0) { employeebank.setInsertDate(date.toString()); employeebank.setUpdateDate(date.toString()); session.save(employeebank); status = 1; } else { Iterator<EmployeeBank> iterator = criteria.list().iterator(); while (iterator.hasNext()) { EmployeeBank empbank = iterator.next(); if (empbank.getDeleteFlag() == true) { empbank.setDeleteFlag(false); empbank.setInsertDate(date.toString()); empbank.setUpdateDate(date.toString()); session.update(empbank); status = 1; } else { return 5; } } } } catch (Exception e) { e.printStackTrace(); } finally { session.getTransaction().commit(); session.close(); } return status; }
// DELETE A EMPLOYEE BANK DETAILS (SOFT DELETE) @Override public int deleteEmployeebank(int empbankId) throws HibernateException, ConstraintViolationException { int status = 0; try { EmployeeBank employeebank = getEmployeeBankId(empbankId); if (employeebank != null) { java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime()); employeebank.setUpdateDate(date.toString()); employeebank.setUpdateBy(null); employeebank.setDeleteFlag(true); updateEmployeeBank(employeebank); status = 1; return status; } else { return status; } } catch (Exception e) { e.printStackTrace(); return status; } }