1

I am using Spring JPA To check if record exists for name and join date:

boolean existsByNameAndJoinDate(String name, LocalDate joinDate);

This works fine but I need to check another property now which is of LocalDateTime. The new field is creation date in db and has a time element but when it is queried it should be just queried with the date element excluding time, so I am trying to amend the above to this

 boolean existsByNameAndJoinDateAndCreationDate(String name, LocalDate joinDate, LocalDate creationDate);

How can I get this to work if anyway whether with native or not?

M06H
  • 1,675
  • 3
  • 36
  • 76
  • If you query with `creationDate = "2020-07-20"`, would it be fair to say that the actual query should then be `creationDate >= "2020-07-20T00:00:00" AND creationDate < "2020-07-21T00:00:00"`? It's the only thing that makes sense, and **that** is the query you need to tell JPA to execute. Converting a `creationDate = date` to `creationDate >= date at midnight AND creationDate < day after date at midnight` it **business-logic**, and should be handled by your Java code, not the JPA code. – Andreas Jul 20 '20 at 16:29
  • 2
    Does this answer your question? [How to query LocalDateTime with LocalDate?](https://stackoverflow.com/questions/43977749/how-to-query-localdatetime-with-localdate) – Ilya Lysenko Jul 20 '20 at 16:33

0 Answers0