HHH-13266 Fix LocalDate serialization by using the proper conversion methods between LocalDate and Timestamp

This commit is contained in:
Yoann Rodière 2019-03-12 11:07:58 +01:00 committed by gbadner
parent 9a8d4f0e5d
commit 1293b5bf70
1 changed files with 15 additions and 1 deletions

View File

@ -63,6 +63,13 @@ public class LocalDateJavaDescriptor extends AbstractTypeDescriptor<LocalDate> {
final LocalDateTime localDateTime = value.atStartOfDay();
if ( Timestamp.class.isAssignableFrom( type ) ) {
/*
* Workaround for HHH-13266 (JDK-8061577).
* We could have done Timestamp.from( localDateTime.atZone( ZoneId.systemDefault() ).toInstant() ),
* but on top of being more complex than the line below, it won't always work.
* Timestamp.from() assumes the number of milliseconds since the epoch
* means the same thing in Timestamp and Instant, but it doesn't, in particular before 1900.
*/
return (X) Timestamp.valueOf( localDateTime );
}
@ -97,7 +104,14 @@ public class LocalDateJavaDescriptor extends AbstractTypeDescriptor<LocalDate> {
if ( Timestamp.class.isInstance( value ) ) {
final Timestamp ts = (Timestamp) value;
return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate();
/*
* Workaround for HHH-13266 (JDK-8061577).
* We used to do LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate(),
* but on top of being more complex than the line below, it won't always work.
* ts.toInstant() assumes the number of milliseconds since the epoch
* means the same thing in Timestamp and Instant, but it doesn't, in particular before 1900.
*/
return ts.toLocalDateTime().toLocalDate();
}
if ( Long.class.isInstance( value ) ) {