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

This commit is contained in:
Yoann Rodière 2019-02-26 12:55:14 +01:00
parent 10f2bca075
commit 3fa7f197a1
1 changed files with 16 additions and 3 deletions

View File

@ -55,8 +55,14 @@ public class LocalDateTimeJavaDescriptor extends AbstractTypeDescriptor<LocalDat
}
if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant();
return (X) java.sql.Timestamp.from( instant );
/*
* Workaround for HHH-13266 (JDK-8061577).
* We used to do Timestamp.from( value.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( value );
}
if ( java.sql.Date.class.isAssignableFrom( type ) ) {
@ -98,7 +104,14 @@ public class LocalDateTimeJavaDescriptor extends AbstractTypeDescriptor<LocalDat
if ( Timestamp.class.isInstance( value ) ) {
final Timestamp ts = (Timestamp) value;
return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() );
/*
* Workaround for HHH-13266 (JDK-8061577).
* We used to do LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ),
* 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();
}
if ( Long.class.isInstance( value ) ) {