LocalDateTime
というフィールドを持つ JPA エンティティ TimeSlot がありstartDateTime
ます。
@Entity
public class TimeSlot {
private LocalDateTime startDateTime;
...
}
WildFly 10.1 で Hibernate を使用しています。startDateTime
と の間startDate
ですべてのエンティティを照会するにはどうすればよい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"),
})