Java - Query Spring with current date

0

I have the following repository with the following method

@Query("SELECT m FROM Money m WHERE m.data = CURRENT_DATE()")
Money findTop1IfHasMoneyInCurrentDate();    

My money class looks like this:

 @Entity
@Table(name="MONEY_DATA", schema="DEMO_PIMS")
@JsonIgnoreProperties(allowGetters=true)
public class Money  {

    @Id
    @Column(name="ID_REG")
    private Long Id;

    @Column(name="DATA")
    @JsonFormat(pattern="dd/MM/yyyy")
    @Temporal(TemporalType.TIMESTAMP)
    private Date data;

    @Column(name="DOLAR")
    private Double dolar;

    @Column(name="EURO")
    private Double euro;

    @Column(name="LIBRA")
    private Double libra;

    public Money() {

    }   

But it is always returning null when I call the "findTop1IfHasMoneyInCurrentDate ()" being that it has records on the current day.

What to do in Query to get a record according to the current day?

    
asked by anonymous 12.07.2018 / 18:03

1 answer

1

According to the Java Persistence API specification, there are predefined functions CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP.

The detail is in using it, which does not take parentheses , common to functions in programming languages. See:

@Query("SELECT m FROM Money m WHERE m.data = CURRENT_DATE")
Money findTop1IfHasMoneyInCurrentDate();    
    
19.07.2018 / 21:19