Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Query matching for current date [duplicate]

Possible Duplicate:
Example of using CURRENT_DATE in JPA query

I am trying to add a query to my repository to compare a date stored in the db against the current date.

My query is like this:

@Query("Select c from Customer c where c.terminated != 1 or c.terminationDate > <currentDate>")
public List<Customer> getTerminatedCustomers();

What can I insert for <currentDate>?

If everything fails I could add a parameter to the method and pass the current date to the query like this. But I would prefer a more elegant solution, if possible.

like image 859
pushy Avatar asked Sep 18 '12 11:09

pushy


1 Answers

This question is actually a duplicate of this one. According to the Java Persistence API specification section 4.6.17.2.3 there are predefined functions CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP. So the query would have to be defined as

 select c from Customer c where c.terminated != 1 or c.terminationDate > CURRENT_DATE
like image 130
Oliver Drotbohm Avatar answered Nov 14 '22 17:11

Oliver Drotbohm