persistentEnrolment.delete(enrolment);
persistentEnrolment.simpleLockWrite(enrolment); enrolment.setEnrolmentState(EnrolmentState.ANNULED);
	private void writeTemporaryEnrolment(EnrolmentContext enrolmentContext) throws ExcepcaoPersistencia {		ISuportePersistente sp = null;		IPersistentEnrolment persistentEnrolment = null;		IPersistentCurricularCourseScope persistentCurricularCourseScope = null;		try {			sp = SuportePersistenteOJB.getInstance();			persistentEnrolment = sp.getIPersistentEnrolment();			persistentCurricularCourseScope = sp.getIPersistentCurricularCourseScope();			List studentEnrolments = persistentEnrolment.readAllByStudentCurricularPlan(enrolmentContext.getStudentActiveCurricularPlan());			// List of all enrolments with state 'enrolled' and 'temporarily enrolled'.			List studentEnroledAndTemporarilyEnroledEnrolments = (List) CollectionUtils.select(studentEnrolments, new Predicate() {				public boolean evaluate(Object obj) {					IEnrolment enrolment = (IEnrolment) obj;					return	(enrolment.getEnrolmentState().equals(EnrolmentState.ENROLED) ||							enrolment.getEnrolmentState().equals(EnrolmentState.TEMPORARILY_ENROLED)) &&							!enrolment.getCurricularCourseScope().getCurricularCourse().getType().equals(CurricularCourseType.OPTIONAL_COURSE_OBJ);				}			});			List enrolmentsToDelete = this.subtract(studentEnroledAndTemporarilyEnroledEnrolments, enrolmentContext.getActualEnrolments(), enrolmentContext.getChosenOptionalDegree());			// Delete from data base the enrolments that don't mather.			Iterator iterator = enrolmentsToDelete.iterator();			while(iterator.hasNext()) {				IEnrolment enrolment = (IEnrolment) iterator.next();				ConfirmActualEnrolmentWithoutRules.deleteAttendAndEnrolmentEvaluations(enrolment);				persistentEnrolment.delete(enrolment);			}			iterator = enrolmentContext.getActualEnrolments().iterator();			while(iterator.hasNext()) {				ICurricularCourseScope curricularCourseScope = (ICurricularCourseScope) iterator.next();				IEnrolment enrolment =					(IEnrolment) persistentEnrolment.readEnrolmentByStudentCurricularPlanAndCurricularCourseScope(						enrolmentContext.getStudentActiveCurricularPlan(),						curricularCourseScope);				if(enrolment == null) {					ICurricularCourseScope curricularCourseScopeToWrite =						(ICurricularCourseScope) persistentCurricularCourseScope.readCurricularCourseScopeByCurricularCourseAndCurricularSemesterAndBranchAndEndDate(							curricularCourseScope.getCurricularCourse(),							curricularCourseScope.getCurricularSemester(),							curricularCourseScope.getBranch(), null);					enrolment = new Enrolment();					enrolment.setCurricularCourseScope(curricularCourseScopeToWrite);					enrolment.setExecutionPeriod(enrolmentContext.getExecutionPeriod());					enrolment.setStudentCurricularPlan(enrolmentContext.getStudentActiveCurricularPlan());					enrolment.setEnrolmentEvaluationType(EnrolmentEvaluationType.NORMAL_OBJ);					enrolment.setEnrolmentState(EnrolmentState.ENROLED);					persistentEnrolment.lockWrite(enrolment);					ChangeEnrolmentStateFromTemporarilyToEnroled.createAttend(enrolment);					ChangeEnrolmentStateFromTemporarilyToEnroled.createEnrolmentEvaluation(enrolment);				} else {					persistentEnrolment.lockWrite(enrolment);					enrolment.setEnrolmentState(EnrolmentState.ENROLED);				}			}		} catch (ExistingPersistentException e1) {			e1.printStackTrace();			throw e1;		} catch (ExcepcaoPersistencia e) {			e.printStackTrace();			throw e;		}	}