Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can anyone point me to an example on how to use CURRENT_DATE in a JPA query?

CURRENT_DATE is specified in JPA but I haven't been able to make it work. I always get the unexpected token [CURRENT_DATE] exception. Since it is specified in JPA all providers should comply with it right?

I'm using EclipseLink 2.0 BTW.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
443 views
Welcome To Ask or Share your Answers For Others

1 Answer

It can be used like so:

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

...where founded is a temporal type:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...