I have this weird phenomenon going in my code. I am using spring data jpa and MySQL database. I have a table named 'Submission' which has date field named 'finishedAt'. The datatype of that field is: 'Date'.
I have a mapped in class in Java:
@Entity
@Table(name = "Submission")
@Getter
@Setter
public class Submission{
//All the fields here
@Temporal(javax.persistence.TemporalType.DATE)
java.util.Date finishedAtValue
}
There is one method which tries to access this date value. When I print the date I see a value of previous day.
Example:
Lets say the date value in database is 2020-06-05 (yyyy-mm-dd)
The code snippet in the method is as follows:
//Code to get the entity from database successfully - submission
log.info("DateTimeAnswer retrieved from database: "+submission.getFinishedAtValue);
/*Expected date value from above log: 2020-06-05
Actual date value from above log: 2020-06-04*/
Not able to understand why this inconsistency while extracting this date value. Any help would be appreciated. Thanks!