I have a JPA entity with a date field is persisted into Mysql DateTime.
Field:
@Column(name = "CREATION_DATE")
private Date creationDate;
Column:
CREATION_DATE datetime DEFAULT NULL,
Setter:
request.setCreationDate(new Date());//Value set to current date
I am getting an strange error that persisted date is 8 hours lesser than the current time. Tried few approaches as below:
Using
@Temporal(TemporalType.TIMESTAMP)for the fieldSetting default TimeZone
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));Printing the date before setting, which displays the correct value.
Setting the timezone at mysql layer as well:
SET GLOBAL time_zone = '+8:00'; SET SESSION time_zone = '+8:00';Changing the field type to
java.sql.Timestamp
none of the above approaches helped. Anyone had a similar issue? Any clue?