if (subject.getIdTeacher().equals(timetable.getTeacher().getIdUser()))
if (subject.getIdTeacher() != null && subject.getIdTeacher().equals(timetable.getTeacher().getIdUser()))
	public Timetable getTimetable(TimetableFilter filter) throws RemoteException, HibernateException {	    Session session = null;        try {            Timetable timetable = new Timetable();            timetable.setBeginPeriod(filter.getBeginPeriod());            timetable.setEndPeriod(filter.getEndPeriod());                        // toutes les matires            Collection allSubjects = get(TABLE_SUBJECT, new SubjectFilter(), Hibernate.getCurrentSession());                        if (filter.getGroup() != null) {                // caractristiques du groupe                GroupDao groupDao = GroupDaoImpl.getInstance();                timetable.setGroup(groupDao.getGroup(filter.getGroup(), null));                                // cours du groupe	            _TakePartGroupSubjectCourseFilter takePartGroupSubjectCourseFilter = new _TakePartGroupSubjectCourseFilter();	            takePartGroupSubjectCourseFilter.setIdGroup(filter.getGroup().getIdGroup());	            Collection list = get(TABLE_ASSOCIATION, takePartGroupSubjectCourseFilter, Hibernate.getCurrentSession());	            timetable.setCourses(new ArrayList());	            for (Iterator i = list.iterator(); i.hasNext(); ) {	                TakePartGroupSubjectCourse takePart = (TakePartGroupSubjectCourse) i.next();	                Course course = new Course(takePart.getIdCourse());	                course = getCourse(course, null);	                if (course.getBeginDate().getTimeInMillis() >= filter.getBeginPeriod().getTimeInMillis() && course.getEndDate().getTimeInMillis() <= filter.getEndPeriod().getTimeInMillis())	                    timetable.addCourse(course);	            }	            	            // caractristiques de la formation du groupe	            FormationDao formationDao = FormationDaoImpl.getInstance();	            timetable.setFormation(formationDao.getFormation(filter.getFormation(), null));	            	            // groupes de la formation	            Group group = new Group();	            group.setIdFormation(filter.getFormation().getIdFormation());	            timetable.setGroups(groupDao.getGroups(new GroupFilter(group)));	            	            // matires de la formation	            for (Iterator i = allSubjects.iterator(); i.hasNext(); ) {	                Subject subject = (Subject) i.next();	                if (subject.getIdFormation().equals(timetable.getFormation().getIdFormation()))	                    timetable.addSubject(subject);	            }            }                        else if (filter.getFormation() != null) {                // caractristiques de la formation	            FormationDao formationDao = FormationDaoImpl.getInstance();	            timetable.setFormation(formationDao.getFormation(filter.getFormation(), null));	            // matires de la formation	            for (Iterator i = allSubjects.iterator(); i.hasNext(); ) {	                Subject subject = (Subject) i.next();	                if (subject.getIdFormation().equals(timetable.getFormation().getIdFormation()))	                    timetable.addSubject(subject);	            }	            // groupes de la formation	            Group group = new Group();	            group.setIdFormation(filter.getFormation().getIdFormation());	            GroupDao groupDao = GroupDaoImpl.getInstance();	            timetable.setGroups(groupDao.getGroups(new GroupFilter(group)));	            	            // cours de la formation	            Course course = new Course();	            course.setIdFormation(filter.getFormation().getIdFormation());	            course.setBeginPeriod(filter.getBeginPeriod());	            course.setEndPeriod(filter.getEndPeriod());	            timetable.setCourses(get(TABLE_COURSE, new CourseFilter(course), Hibernate.getCurrentSession()));	            	            // responsable de la formation	            UserFilter userFilter = new UserFilter();	            userFilter.setIdUser(timetable.getFormation().getIdTeacher());	            userFilter.setUserType(UserDao.TYPE_TEACHER);	            UserDao userDao = UserDaoImpl.getInstance();	            Collection c = userDao.getUsers(userFilter);	            timetable.setPersonInCharge((User) c.toArray()[0]);            }                        else if (filter.getTeacher() != null) {                // caractristiques de l'enseignant                UserDao userDao = UserDaoImpl.getInstance();                timetable.setTeacher(userDao.getUser(filter.getTeacher(), null));                // matires de l'enseignant	            for (Iterator i = allSubjects.iterator(); i.hasNext(); ) {	                Subject subject = (Subject) i.next();	                if (subject.getIdTeacher().equals(timetable.getTeacher().getIdUser()))	                    timetable.addSubject(subject);	            }	            	            // cours de l'enseignant	            _IsDirectedByCourseTeacherFilter isDirectedByCourseTeacherFilter = new _IsDirectedByCourseTeacherFilter();	            isDirectedByCourseTeacherFilter.setIdTeacher(filter.getTeacher().getIdUser());	            Collection isDirectedByCourseTeachers = get(TABLE_ISDIRECTING, isDirectedByCourseTeacherFilter, Hibernate.getCurrentSession());	            timetable.setCourses(new ArrayList());	            for (Iterator i = isDirectedByCourseTeachers.iterator(); i.hasNext(); ) {	                Course course = ((IsDirectedByCourseTeacher) i.next()).getIdCourse();	                if (course.getBeginDate().getTimeInMillis() >= filter.getBeginPeriod().getTimeInMillis() && course.getEndDate().getTimeInMillis() <= filter.getEndPeriod().getTimeInMillis())	                    timetable.addCourse(course);	            }            }                        else if (filter.getRoom() != null) {                // caractristiques du local                ElementDao elementDao = ElementDaoImpl.getInstance();                timetable.setRoom(elementDao.getRoom(filter.getRoom(), null));                                // cours du local                timetable.setCourses(elementDao.getCoursesInRoom(timetable.getRoom(), filter.getBeginPeriod(), filter.getEndPeriod()));            }                        else if (filter.getMaterial() != null) {                // caractristiques du matriel                ElementDao elementDao = ElementDaoImpl.getInstance();                timetable.setMaterial(elementDao.getMaterial(filter.getMaterial(), null));                                // cours du matriel                timetable.setCourses(elementDao.getCoursesWithMaterial(timetable.getMaterial(), filter.getBeginPeriod(), filter.getEndPeriod()));            }            UserDao userDao = UserDaoImpl.getInstance();            for (Iterator i = timetable.getCoursesNotArranged().iterator(); i.hasNext(); ) {                Course tmp = (Course) i.next();                                // matire correspondante pour chaque cours                _TakePartGroupSubjectCourseFilter f = new _TakePartGroupSubjectCourseFilter();                f.setIdCourse(tmp.getIdCourse());                Collection co = get(TABLE_ASSOCIATION, f, Hibernate.getCurrentSession());                if (co != null && co.size() > 0) {	                TakePartGroupSubjectCourse takePart = (TakePartGroupSubjectCourse) co.toArray()[0];	                for (Iterator j = allSubjects.iterator(); j.hasNext(); ) {	                    Subject s = (Subject) j.next();	                    if (s.getIdSubject().equals(takePart.getIdSubject()))	                        tmp.setSubject(s);	                }                }                                // enseignants correspondants pour chaque cours                Collection teachers = tmp.getTeachersDirecting();                for (Iterator j = teachers.iterator(); j.hasNext(); ) {                    IsDirectedByCourseTeacher isDirected = (IsDirectedByCourseTeacher) j.next();                    tmp.addTeacher(userDao.getUser(new User(isDirected.getIdTeacher()), null));                }                if (tmp.getTeachers() == null)                    tmp.setTeachers(new HashSet());            }            return timetable;        } finally {            Hibernate.closeSession();        }	}