0

我需要将此 SQL 语句转换为 HQL,但我认为 NOT EXISTS 在 HQL 中不起作用请帮助我!!!

SELECT doctor.idUser, schedule.idSchedule, schedule.timeStart, schedule.day
FROM doctor, schedule
    WHERE schedule.day='LUNES'
        AND schedule.timeStart > '08:00:00'
        AND doctor.idUser= '1'
        AND doctor.idUser = schedule.idUserDoctor
AND NOT EXISTS( SELECT *    FROM appointment
    WHERE schedule.idSchedule = appointment.idSchedule
        AND doctor.idUser = schedule.idUserDoctor
        AND appointment.appointmentDate ='2012-09-06')
AND NOT EXISTS ( SELECT * FROM temporaryschedule
        WHERE schedule.idSchedule = temporaryschedule.idSchedule
        AND doctor.idUser = schedule.idUserDoctor"
        AND temporaryschedule.appointmentDate='201-09-06')
ORDER BY schedule.timeStart ASC
4

1 回答 1

4

不幸的是,您没有提供有关您的域模型的任何信息,因此我们必须在这里做出一些假设......首先,我没有考虑医生和日程安排之间的任何映射关联,尽管您可能想要映射它。根据良好的设计,我使用参数而不是文字。我假设所有引用的表都已映射,并且正在为类使用“逻辑名称映射”。最后,我使用你的列名作为域模型属性名......

select ...
from Doctor d, Schedule s
where s.day = :day
  and s.timeStart > :startTime
  and d.idUser = :doctorId
  and d.idUser = s.idUserDoctor
  and not exists (
      select *
      from Appointment appt
      where s.idSchedule = appt.idSchedule
        and d.idUser = s.idUserDoctor
        and apt.appointmentDate = :apptDate
  )
  and not exists (
      select *
      from TemporarySchedule ts
      where s.idSchedule = ts.idSchedule
        and d.idUser = s.idUserDoctor
        and ts.appointmentDate = tempSchedDate
  )
order by s.startTime asc
于 2012-09-12T05:19:28.230 回答