@Override public Boolean execute(OnlineSectioningServer server, OnlineSectioningHelper helper) { StudentSectioningStatus status = (hasStatus() ? (StudentSectioningStatus) helper .getHibSession() .createQuery("from StudentSectioningStatus where reference = :ref") .setString("ref", getStatus()) .uniqueResult() : null); for (Long studentId : getStudentIds()) { Lock lock = server.lockStudent(studentId, null, name()); try { XStudent student = server.getStudent(studentId); helper.beginTransaction(); try { Student dbStudent = StudentDAO.getInstance().get(studentId, helper.getHibSession()); if (student != null && dbStudent != null) { OnlineSectioningLog.Action.Builder action = helper.addAction(this, server.getAcademicSession()); action.setStudent( OnlineSectioningLog.Entity.newBuilder() .setUniqueId(student.getStudentId()) .setExternalId(student.getExternalId()) .setName(student.getName())); if (status != null) { action.addOther( OnlineSectioningLog.Entity.newBuilder() .setUniqueId(status.getUniqueId()) .setName(status.getLabel()) .setExternalId(status.getReference()) .setType(OnlineSectioningLog.Entity.EntityType.OTHER)); } student.setStatus(getStatus()); dbStudent.setSectioningStatus(status); helper.getHibSession().saveOrUpdate(dbStudent); server.update(student, false); } helper.commitTransaction(); } catch (Exception e) { helper.rollbackTransaction(); if (e instanceof SectioningException) throw (SectioningException) e; throw new SectioningException(MSG.exceptionUnknown(e.getMessage()), e); } } finally { lock.release(); } } return true; }