- I have a table in oracle db.The table contains a column last_updt_dt with a datatype Date.
I am using spring data jpa with hibernate version 5.3.12 final. The entity class for table contains date field as below
@Column(name = "last_updt_dt") private LocalDateTime lastUpdtDt;
If I insert date through my application and retrieve it , then it shows expected behavior. For Ex, in database, it shows following value (with 24hr format)
28-04-2020 00:32:02
and in the application, if my server timezone is AEST, then it shows the above value as
2020-04-28T10:32:02
which is correct ( the utc value in db and AEST value received in my application are matching correctly)
But, I have some existing records in the same database table. If I try to retrieve these records, then in my application, the date shows wrong value. For Ex, the database table shows following value (with 24hr format)
11-01-2017 09:36:34
and in the application, if my server timezone is AEST, then it shows the above value as
2017-01-11T20:36:34
if I convert this utc time 09:36:34 to AEST time, then it gives me time as 19:36:34 and what I am seeing here is 20:36:34 which is one hour extra.
So, I am unable to understand the behavior :
- If I insert date from my spring boot application and retrieve it, the date entered in db is consistent with the one returned by jpa
- but if I try to read date which is not inserted by my application, which is already present in db, then the date returned by jpa is not matching with db value,in fact, its showing me a one hour extra as compared to expected value. This is happening for all the existing date value in that table. (not the one entered by my spring boot application)
Anyone having any clue about this behavior?
My application is created using jhipster 6.4.1 and I observed that there is a DateTimeFormatConfiguration class containing following method
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(registry);
}
Not sure, if this is playing any role.
Instant
for storing dates or timestamps in the database. – Jens Schauder