3
query = em.createQuery("SELECT COUNT(a) FROM Appointment a WHERE a.datetime >= ?1 and a.datetime < ?2"); query.setParameter(1, date1, TemporalType.DATE); query.setParameter(1, date2, TemporalType.DATE); 

So JPQL does not have a DATE() function.
I've tried a.startDate >= day1 AND a.startDate < nextday but it is returning the count of every single appointment

5
  • Yes. The ?1 is for the parameter value. The error is marking the first parenthesis in DATE(a.startDate) Commented Nov 21, 2015 at 2:34
  • startDate is DATETIME Commented Nov 21, 2015 at 2:37
  • what is count(a) ? shouldn't be count(a.*) ? Commented Nov 21, 2015 at 2:52
  • Because DATE is not a valid JPQL function. Read the JPA spec and any decent JPQL docs Commented Nov 21, 2015 at 3:35
  • what is the SQL generated? Commented Nov 21, 2015 at 7:55

1 Answer 1

1

This query:

SELECT COUNT(a) FROM Appointment a WHERE DATE(a.startDate) = ?1 

only makes sense of there is a column called a in Appointment. That is unlikely. You probably intend:

SELECT COUNT(*) FROM Appointment a WHERE DATE(a.startDate) = ?1 
Sign up to request clarification or add additional context in comments.

1 Comment

@Entity . . . Your question has the "mysql" tag. And, that syntax doesn't really make sense in MySQL.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.