开发者

JPQL SELECT between date statement [closed]

开发者 https://www.devze.com 2023-02-17 20:15 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
开发者_运维知识库

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 6 years ago.

Improve this question

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


public List<Student> findStudentByReports(Date startDate, Date endDate) {
    System.out.println("call findStudentMethd******************with this pattern"
                    + startDate
                    + endDate
                    + "*********************************************");

    return em
            .createQuery(
                    "' select attendence from Attendence attendence where attendence.admissionDate BETWEEN : startDate '' AND endDate ''"
                            + "'")
            .setParameter("startDate", startDate, TemporalType.DATE)
            .setParameter("endDate", endDate, TemporalType.DATE)
            .getResultList();

}
0

精彩评论

暂无评论...
验证码 换一张
取 消