I would like to convert this SQL statement to a JPQL equivalent.
SELECT * FROM events
WHERE events_date BETWEEN '2011-01-01' AND '2011-03-31';
This correctly retrieves the information from the table events
.
In my Events
entity
@Column(name = "events_date")
@Temporal(TemporalType.DATE)
private Date eventsDate;
So far this is what I have but it is not working.
public List<Events> findAllEvents(Date startDate, Date endDate) {
List<Events> allEvents = entityManager.createQuery(
"SELECT e FROM Events e WHERE t.eventsDate BETWEEN :startDate AND :endDate")
.setParameter("startDate", startDate, TemporalType.DATE)
.setParameter("endDate", endDate, TemporalType.DATE)
.getResultList();
return allEvents ;
}
What am I doing wrong? Thanks.
Try this query (replace t.eventsDate
with e.eventsDate
):
SELECT e FROM Events e WHERE e.eventsDate BETWEEN :startDate AND :endDate