System.out.println("Deleting teacher service items."); for (final Set<TeacherServiceItem> teacherServiceItems = rootDomainObject.getTeacherServiceItemsSet(); !teacherServiceItems.isEmpty(); teacherServiceItems.iterator().next().delete());  System.out.println("Deleting teacher services."); for (final Set<TeacherService> teacherServices = rootDomainObject.getTeacherServicesSet(); !teacherServices.isEmpty(); teacherServices.iterator().next().delete());
    private static void clearData() {        final RootDomainObject rootDomainObject = RootDomainObject.getInstance();        System.out.println("Deleting events.");        for (final Set<Event> events = rootDomainObject.getAccountingEventsSet(); !events.isEmpty(); events.iterator().next().delete());        System.out.println("Deleting service agreements.");        for (final Set<ServiceAgreement> serviceAgreements = rootDomainObject.getServiceAgreementsSet(); !serviceAgreements.isEmpty(); serviceAgreements.iterator().next().delete());        System.out.println("Deleting posting rules.");        for (final Set<PostingRule> postingRules = rootDomainObject.getPostingRulesSet(); !postingRules.isEmpty(); postingRules.iterator().next().delete());        System.out.println("Deleting service agreement templates.");        for (final Set<ServiceAgreementTemplate> serviceAgreementTemplateSet = rootDomainObject.getServiceAgreementTemplatesSet(); !serviceAgreementTemplateSet.isEmpty(); serviceAgreementTemplateSet.iterator().next().delete());        System.out.println("Deleting writtenEvaluation enrolments.");        for (final Set<WrittenEvaluationEnrolment> writtenEvaluationEnrolment = rootDomainObject.getWrittenEvaluationEnrolmentsSet(); !writtenEvaluationEnrolment.isEmpty(); writtenEvaluationEnrolment.iterator().next().delete());        System.out.println("Deleting students from shifts.");        if (!rootDomainObject.getShiftsSet().isEmpty()) {            for (final Iterator<Shift> shiftIterator = rootDomainObject.getShiftsSet().iterator(); !shiftIterator.hasNext(); ) {                final Shift shift = shiftIterator.next();                for (final Set<Registration> registrations = shift.getStudentsSet(); !registrations.isEmpty(); registrations.remove(registrations.iterator().next()));            }            for (final Shift shift : rootDomainObject.getShiftsSet()) {                if (!shift.getStudentsSet().isEmpty()) {                    shift.getStudentsSet().clear();                }            }        }        for (final Set<StudentGroup> studentGroups = rootDomainObject.getStudentGroupsSet(); !studentGroups.isEmpty(); studentGroups.iterator().next().delete());        System.out.println("Deleting student data by execution year.");        for (final Set<StudentDataByExecutionYear> data = rootDomainObject.getStudentDataByExecutionYearSet(); !data.isEmpty(); data.iterator().next().delete());        System.out.println("Deleting attends.");        for (final Set<Attends> attends = rootDomainObject.getAttendssSet(); !attends.isEmpty(); attends.iterator().next().delete());        System.out.println("Deleting enrolment periods.");        for (final Set<EnrolmentPeriod> enrolmentPeriods = rootDomainObject.getEnrolmentPeriodsSet(); !enrolmentPeriods.isEmpty(); enrolmentPeriods.iterator().next().delete());        System.out.println("Deleting curriculum modules.");        for (final Set<CurriculumModule> curriculumModules = rootDomainObject.getCurriculumModulesSet(); !curriculumModules.isEmpty(); curriculumModules.iterator().next().delete());        System.out.println("Deleting student curricular plans.");        for (final Set<StudentCurricularPlan> studentCurricularPlans = rootDomainObject.getStudentCurricularPlansSet(); !studentCurricularPlans.isEmpty(); studentCurricularPlans.iterator().next().delete());        System.out.println("Deleting registrations.");        for (final Set<Registration> registrations = rootDomainObject.getRegistrationsSet(); !registrations.isEmpty(); registrations.iterator().next().delete());        System.out.println("Deleting students.");        for (final Set<Student> students = rootDomainObject.getStudentsSet(); !students.isEmpty(); students.iterator().next().delete());        System.out.println("Deleting school classes.");        for (final Set<SchoolClass> schoolClasses = rootDomainObject.getSchoolClasssSet(); !schoolClasses.isEmpty(); schoolClasses.iterator().next().delete());        System.out.println("Deleting lessons.");        for (final Set<Lesson> lessons = rootDomainObject.getLessonsSet(); !lessons.isEmpty(); lessons.iterator().next().delete());        System.out.println("Deleting shifts.");        for (final Set<Shift> shifts = rootDomainObject.getShiftsSet(); !shifts.isEmpty(); shifts.iterator().next().delete());        System.out.println("Deleting evaluation methods.");        for (final Set<EvaluationMethod> evaluationMethods = rootDomainObject.getEvaluationMethodsSet(); !evaluationMethods.isEmpty(); evaluationMethods.iterator().next().delete());        System.out.println("Deleting bibliographic references.");        for (final Set<BibliographicReference> bibliographicReferences = rootDomainObject.getBibliographicReferencesSet(); !bibliographicReferences.isEmpty(); bibliographicReferences.iterator().next().delete());        System.out.println("Deleting execution course sites.");        for (final Set<ExecutionCourseSite> sites = rootDomainObject.getExecutionCourseSitesSet(); !sites.isEmpty(); sites.iterator().next().delete());        System.out.println("Deleting forums.");        for (final Set<Forum> forums = rootDomainObject.getForunsSet(); !forums.isEmpty(); forums.iterator().next().delete());        System.out.println("Deleting announcements.");        for (final Set<Announcement> announcements = rootDomainObject.getAnnouncementsSet(); !announcements.isEmpty(); announcements.iterator().next().delete());        System.out.println("Deleting announcement boards.");        for (final Set<AnnouncementBoard> announcementBoards = rootDomainObject.getAnnouncementBoardsSet(); !announcementBoards.isEmpty(); announcementBoards.iterator().next().delete());        System.out.println("Deleting lesson plannings.");        for (final Set<LessonPlanning> lessonPlannings = rootDomainObject.getLessonPlanningsSet(); !lessonPlannings.isEmpty(); lessonPlannings.iterator().next().deleteWithoutReOrder());        System.out.println("Deleting evaluations.");        for (final Set<Evaluation> evaluations = rootDomainObject.getEvaluationsSet(); !evaluations.isEmpty(); evaluations.iterator().next().delete());        System.out.println("Deleting professorships.");        for (final Set<Professorship> professorships = rootDomainObject.getProfessorshipsSet(); !professorships.isEmpty(); professorships.iterator().next().delete());        System.out.println("Deleting execution courses.");        for (final Set<ExecutionCourse> executionCourses = rootDomainObject.getExecutionCoursesSet(); !executionCourses.isEmpty(); executionCourses.iterator().next().delete());        System.out.println("Deleting coordinators.");        for (final Set<Coordinator> coordinators = rootDomainObject.getCoordinatorsSet(); !coordinators.isEmpty(); coordinators.iterator().next().delete());        System.out.println("Deleting teachers.");        for (final Set<Teacher> teachers = rootDomainObject.getTeachersSet(); !teachers.isEmpty(); teachers.iterator().next().delete());        for (final Iterator<Accountability> acountabilityIterator = RootDomainObject.getInstance().getAccountabilitysIterator(); acountabilityIterator.hasNext(); ) {            final Accountability accountability = acountabilityIterator.next();            if (accountability instanceof Contract) {                acountabilityIterator.remove();                accountability.delete();            }        }        System.out.println("Deleting employees.");        for (final Set<Employee> employees = rootDomainObject.getEmployeesSet(); !employees.isEmpty(); employees.iterator().next().delete());        System.out.println("Deleting person roles.");        for (final Party party : rootDomainObject.getPartysSet()) {            if (party.isPerson()) {                final Person person = (Person) party;                person.getPersonRolesSet().clear();            }        }        System.out.println("Deleting identifications.");        for (final Set<Identification> identifications = rootDomainObject.getIdentificationsSet(); !identifications.isEmpty(); identifications.iterator().next().delete());        System.out.println("Deleting users.");        for (final Set<User> users = rootDomainObject.getUsersSet(); !users.isEmpty(); users.iterator().next().delete());        System.out.println("Deleting accounts.");        for (final Set<Account> accounts = rootDomainObject.getAccountsSet(); !accounts.isEmpty(); accounts.iterator().next().delete());        System.out.println("Deleting people.");        for (final Set<Party> parties = new HashSet<Party>(rootDomainObject.getPartysSet()); !parties.isEmpty(); ) {            final Party party = parties.iterator().next();            if (party.isPerson()) {                final Person person = (Person) party;                person.delete();            }            parties.remove(party);        }        System.out.println("Deleting execution degrees.");        for (final Set<ExecutionDegree> executionDegrees = rootDomainObject.getExecutionDegreesSet(); !executionDegrees.isEmpty(); executionDegrees.iterator().next().delete());        System.out.println("Deleting curricular course scopes.");        for (final Set<CurricularCourseScope> curricularCourseScopes = rootDomainObject.getCurricularCourseScopesSet(); !curricularCourseScopes.isEmpty(); curricularCourseScopes.iterator().next().delete());        System.out.println("Deleting degree modules.");        for (final Set<DegreeModule> degreeModules = rootDomainObject.getDegreeModulesSet(); !degreeModules.isEmpty(); degreeModules.iterator().next().delete());        System.out.println("Deleting branches.");        for (final Set<Branch> branches = rootDomainObject.getBranchsSet(); !branches.isEmpty(); branches.iterator().next().delete());        System.out.println("Deleting degree curricular plans.");        for (final Set<DegreeCurricularPlan> degreeCurricularPlanss = rootDomainObject.getDegreeCurricularPlansSet(); !degreeCurricularPlanss.isEmpty(); degreeCurricularPlanss.iterator().next().delete());        System.out.println("Deleting degree infos.");        for (final Set<DegreeInfo> degreeInfos = rootDomainObject.getDegreeInfosSet(); !degreeInfos.isEmpty(); degreeInfos.iterator().next().delete());        System.out.println("Deleting degrees.");        for (final Set<Degree> degrees = rootDomainObject.getDegreesSet(); !degrees.isEmpty(); degrees.iterator().next().delete());        System.out.println("Deleting execution years.");        for (final Set<ExecutionYear> executionYears = rootDomainObject.getExecutionYearsSet(); !executionYears.isEmpty(); executionYears.iterator().next().delete());        System.out.println("Deleting occupation periods.");        for (final Set<OccupationPeriod> occupationPeriods = rootDomainObject.getOccupationPeriodsSet(); !occupationPeriods.isEmpty(); occupationPeriods.iterator().next().deleteIfEmpty());        System.out.println("Deleting spaces.");        for (final Set<Space> spaces = rootDomainObject.getSpacesSet(); !spaces.isEmpty(); spaces.iterator().next().delete());        System.out.println("Deleting campi.");        for (final Set<Campus> campi = rootDomainObject.getCampussSet(); !campi.isEmpty(); campi.iterator().next().delete());        System.out.println("Deleting administrative offices.");        for (final Set<AdministrativeOffice> administrativeOffices = rootDomainObject.getAdministrativeOfficesSet(); !administrativeOffices.isEmpty(); administrativeOffices.iterator().next().delete());        System.out.println("Deleting administrative offices.");        for (final Set<Department> departments = rootDomainObject.getDepartmentsSet(); !departments.isEmpty(); departments.iterator().next().delete());        System.out.println("Completed clearing any existing data.");        System.out.println("Loading the test data...");    }