我有一个 JPA 实体 TimeSlot,其LocalDateTime
字段名为startDateTime
:
@Entity
public class TimeSlot {
private LocalDateTime startDateTime;
...
}
我在 WildFly 10.1 上使用休眠。如何使用startDateTime
betweenstartDate
和查询所有实体endDate
?
private List<TimeSlot> getTimeSlotsByStartDateEndDate(LocalDate startDate, LocalDate endDate) {
return entityManager.createNamedQuery("TimeSlot.findByStartDateEndDate", TimeSlot.class)
.setParameter("startDate", startDate)
.setParameter("endDate", endDate).getResultList());
}
此查询失败,因为时间戳不是日期:
@NamedQueries({
@NamedQuery(name = "TimeSlot.findByStartDateEndDate",
query = "select t from TimeSlot t" +
// fails because a timestamp is not a date
" where t.startDateTime between :startDate and :endDate"),
})