0

I have a table in PostgreSQL that stores dob as datatype timestamp without timezone example value '1997-12-03 07:00:00'.

My entity class is as follows

    @Table(name = "customer")
    public class Customer implements Serializable{ 
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE)
        @Column(name = "id",unique = true)
        private Long id;

    
        @Column(name = "username")
        @NotNull(message = "username cannot be empty")
        private String username ;

        @Column(name = "dob")
        @JsonFormat(pattern="yyyy-MM-dd")
        private Date dob; 
    }

I want to find all users with dob '1997-12-03'. But as it has a timestamp it's not returning any value. How it can get dob without timestamp using query without changing the datatype of dob?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
sia
  • 1
  • `@Temporal(TemporalType.DATE)` – XtremeBaumer May 13 '22 at 07:19
  • Does this answer your question? [What is the use of the @Temporal annotation in Hibernate?](https://stackoverflow.com/questions/25333711/what-is-the-use-of-the-temporal-annotation-in-hibernate) – XtremeBaumer May 13 '22 at 07:19
  • The example in your prose shows a date with a time of day, but your code shows a JSON format for date-only. Which is correct? – Basil Bourque May 13 '22 at 07:26
  • If you're storing a timestamp, then that instant in time will have happened on different dates in different time zones - which time zone are you interested in?# – Jon Skeet May 13 '22 at 07:26
  • 1
    Both `Date` classes are terribly flawed, and were supplanted years ago by the modern *java.time* classes defined in JSR 310. Specifically replaced by `LocalDate` and `Instant`. – Basil Bourque May 13 '22 at 07:28
  • @JonSkeet its storing different timestamps instead of UTC(00:00:00). – sia May 13 '22 at 07:39
  • 1
    That doesn't really answer the question. A timestamp represents an instant in time. Right now, it's 2022-05-13T07:41:00Z. That's May 13th here in the UK (at 8:41am) but in Hawaii for example, it's May 12th at 9:41pm. So if that timestamp ended up in the database, would you want to treat it as May 12th or May 13th? – Jon Skeet May 13 '22 at 07:42

0 Answers0