Example of using CURRENT_DATE in JPA query

前端 未结 3 875
小蘑菇
小蘑菇 2020-12-18 23:18

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 m

相关标签:
3条回答
  • 2020-12-18 23:54

    The answer to this question was retrieving the values via JPA and then do the math in plain Java.

    0 讨论(0)
  • 2020-12-18 23:57

    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

    0 讨论(0)
  • 2020-12-18 23:58

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

    0 讨论(0)
提交回复
热议问题