0

I have a spring boot application that uses spring data jpa, hibernate and data is stored in MySQL. I have set the timezone to UTC using spring.jpa.properties.hibernate.jdbc.time_zone=UTC . The date property is defined as following in the model entity class

@NotNull
@Column(nullable = false)
@Temporal(TemporalType.DATE)
private Date startDate;

So if I am passing date as "startDate": "2019-10-05" in my Rest API, the date value is stored as "2019-10-04" in the database. I want the Date to be stored as "2019-10-05". I want the timezone conversion to be applied only for timestamp fields ? is it possible?

Edit: The issue for me is the data is getting converted to UTC. But I only want Objects with TimeStamp to be converted to UTC and not the date Objects

Sam
  • 1,298
  • 6
  • 30
  • 65
  • Possible duplicate of [How to store date/time and timestamps in UTC time zone with JPA and Hibernate](https://stackoverflow.com/questions/508019/how-to-store-date-time-and-timestamps-in-utc-time-zone-with-jpa-and-hibernate) – Ashu Oct 11 '19 at 08:24
  • If you can avoid the `Date` class, do. It is poorly designed and long outdated. Instead use `LocalDate` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Oct 11 '19 at 08:48

0 Answers0