CURRENT_DATE example in a JPA query

Can someone give me an example of using CURRENT_DATE in a JPA query?

CURRENT_DATE is specified in JPA, but I could not get it to work. I always get an unexpected token [CURRENT_DATE] exception unexpected token [CURRENT_DATE] . Since this is stated in the JPA, should all providers comply with this correctly?

I am using EclipseLink 2.0 BTW.

+7
java jpa eclipselink
source share
3 answers

It can be used like this:

 Query query = manager .createQuery("SELECT c FROM CITIES c WHERE c.founded = CURRENT_DATE"); for (Object city : query.getResultList()) { System.out.println(city); } 

... where the temporary type is set:

  @Column(name = "FOUNDED") @Temporal(TemporalType.DATE) private Date founded = new Date(); 

Not a great example, but you get the idea. I am using Eclipselink 1.1.2

+12
source share

The answer to this question was to get values ​​through JPA and then do the math in plain Java.

+4
source share

If you are using the Expression Framework , there is an Expression currentDateDate() method Expression currentDateDate() of the Expression object ( org.eclipse.persistence.expressions.Expression ).

+3
source share

All Articles