1

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"),
})
4

1 に答える 1