startCriteria.addGreaterThan("shift.associatedLessons.inicio", startTimeCalendar); startCriteria.addLessThan("shift.associatedLessons.inicio", endTimeCalendar);
startCriteria.addGreaterThan("shift.associatedLessons.begin", startTimeCalendar.getTime()); startCriteria.addLessThan("shift.associatedLessons.begin", endTimeCalendar.getTime());
    public List readOverlappingPeriod(Integer teacherId, Integer executionPeriodId,            DiaSemana weekDay, Date startTime, Date endTime) throws ExcepcaoPersistencia {        Criteria criteria = new Criteria();        criteria.addEqualTo("professorship.executionCourse.keyExecutionPeriod", executionPeriodId);        criteria.addEqualTo("professorship.keyTeacher", teacherId);        criteria.addEqualTo("shift.associatedLessons.diaSemana", weekDay);        criteria.addEqualTo("percentage", new Double(100));        Calendar startTimeCalendar = Calendar.getInstance();        startTimeCalendar.setTime(startTime);        Calendar endTimeCalendar = Calendar.getInstance();        endTimeCalendar.setTime(endTime);        Criteria startCriteria = new Criteria();        startCriteria.addGreaterThan("shift.associatedLessons.inicio", startTimeCalendar);        startCriteria.addLessThan("shift.associatedLessons.inicio", endTimeCalendar);        Criteria endCriteria = new Criteria();        endCriteria.addGreaterThan("shift.associatedLessons.fim", startTimeCalendar);        endCriteria.addLessThan("shift.associatedLessons.fim", endTimeCalendar);        Criteria equalCriteria = new Criteria();        equalCriteria.addEqualTo("shift.associatedLessons.inicio", startTimeCalendar);        equalCriteria.addEqualTo("shift.associatedLessons.fim", endTimeCalendar);        Criteria timeCriteria = new Criteria();        timeCriteria.addOrCriteria(startCriteria);        timeCriteria.addOrCriteria(endCriteria);        timeCriteria.addOrCriteria(equalCriteria);        criteria.addAndCriteria(timeCriteria);        return queryList(ShiftProfessorship.class, criteria);    }