I am reaching out to the community here because either I found an issue with Hibernate or I just don't understand how to use java.sql.Date
and java.time.LocalDate
.
I'm running into a problem where my DB is in UTC time zone while my client is in EST. I have a field in the DB called ETA
of type DATE
that for example is set to 2019-09-10
on a record. When I read the date in EST it becomes 2019-09-09
. The DATE
field according to documentation has no timezone information.
When Hibernate reads the value, it uses the DateTypeDescriptor.java
class. However, the problem with that class is that it will first try to read the value as a java.sql.Date
(in the rs.getDate( name )
part) and then call java.sql.Date.toLocalDate()
in the javaTypeDescriptor.wrap()
part, which is implemented poorly because what it does is it strips off the timezone offset information and just plainly returns a date. This makes 2019-09-09T20:00:00.000-0400
(which is 2019-09-10
in the database) to become 2019-09-09
without the timezone offset part.
What I consider the problem is the part where Hibernate calls rs.getDate()
because that must return java.sql.Date
. Now, the MySQL driver contains a method public LocalDate getLocalDate(int columnIndex)
to obtain a LocalDate
, so I don't understand why Hibernate isn't using that method.
I found that someone has already brought up this same problem with them but they don't seem to consider it an issue.
Therefore, I'm reaching out here to understand - is there a bug with Hibernate or am I just not understanding correctly how to convert between DATE
(DB) and LocalDate
(Java) types.
PS: I use latest Hibernate 5.4.5 and latest JPA 2.2.