TimestampTypeDescriptor instead of DateTypeDescriptor used in value binding when a JPA attribute converter to convert LocalDate to java.sql.Date is implied


Because Hibernate doesn't take in charge neither LocalDate.MIN nor LocalDate.MAX, we have written a JPA attribute converter between LocalDate and java.sql.Date in order to take into account these peculiar values. This converter is declared as to be auto-applied.

Without the converter, any attribute of a JPA entity that is a LocalDate is correctly treated by Hibernate in selecting DateTypeDescriptor to perform the binding of the value.

With the converter enabled, although the attribute is working on LocalDate and on java.sql.Date, once the conversion done, AttributeConverterSqlTypeDescriptorAdapter uses TimestampTypeDescriptor as real binder instead of DateTypeDescriptor. This is a problem when a timezone is explicitly set (to UTC in our case) with the Hibernate property hibernate.jdbc.time_zone because the following code is then invoked:

and then the value is modified. For example, "1984-01-01" becomes "1983-12-31"! (The timezone of the platform is in “Europe/Paris”.)

When this value is read from the database, the following code is invoked:

and the returned value is "1983-12-31 01:00:00.0" and then translated to a java.sql.Date of "1983-12-31" before passing it to our attribute converter.


Hibernate 5.3.20 in Wildfly 23.0.1
OpenJdk version "11.0.10" 2021-01-19
H2 1.4.197 in in Wildfly
Bug detected in an integration tests with Arquillian
OS Linux Ubuntu 20.04.2 LTS
TimeZone set in "Europe/Paris"




Miguel Moquillon