spring 如何在Hibernate SQL中从LocalTime中减去Duration

vd2z7a6w  于 2023-04-10  发布在  Spring
关注(0)|答案(1)|浏览(174)

我在Hibernate的AppointmentEntity实体中有一个名为mobileAdditionalDurationDuration字段。在我的AppointmentRepository接口中,我试图编写一个SQL查询,从startTimeendTime字段中减去此持续时间,它们的类型为LocalTime
下面是我写的查询:

  1. @Query(
  2. value = """
  3. SELECT EXISTS (
  4. SELECT
  5. a.date,
  6. SUBTIME(a.startTime, a.mobileAdditionalDuration) as startTime1,
  7. SUBTIME(a.endTime, a.mobileAdditionalDuration) as endTime1
  8. FROM appointment a
  9. WHERE (a.date = ?1) AND ((startTime1 < ?2 AND endTime1 > ?2) OR (startTime1 < ?3 AND endTime1 > ?3))
  10. )
  11. """
  12. )
  13. fun checkIfAppointmentAlreadyExistAtThisTime(date: LocalDate, start: LocalTime, end: LocalTime): Boolean

然而,当我运行查询时,我得到了异常Could not interpret path expression 'aStartTime'。有人能帮助我纠正我的查询以获得所需的结果吗?

8qgya5xd

8qgya5xd1#

HQL -运算符用于从LocalTime中减去Duration,如下所述:
https://docs.jboss.org/hibernate/orm/6.2/userguide/html_single/Hibernate_User_Guide.html#hql-Datetime-arithmetic

相关问题