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

This commit is contained in:
Yoann Rodière 2019-03-01 13:32:16 +01:00 committed by gbadner
parent c6cea4ce3d
commit a17e9fc494
1 changed files with 14 additions and 2 deletions

View File

@ -61,7 +61,13 @@ public class InstantJavaDescriptor extends AbstractTypeDescriptor<Instant> {
}
if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
return (X) Timestamp.from( instant );
/*
* Workaround for HHH-13266 (JDK-8061577).
* Ideally we'd want to use Timestamp.from(), but this 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( instant.atZone( ZoneId.systemDefault() ).toLocalDateTime() );
}
if ( java.sql.Date.class.isAssignableFrom( type ) ) {
@ -95,7 +101,13 @@ public class InstantJavaDescriptor extends AbstractTypeDescriptor<Instant> {
if ( Timestamp.class.isInstance( value ) ) {
final Timestamp ts = (Timestamp) value;
return ts.toInstant();
/*
* Workaround for HHH-13266 (JDK-8061577).
* Ideally we'd want to use ts.toInstant(), but this 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().atZone( ZoneId.systemDefault() ).toInstant();
}
if ( Long.class.isInstance( value ) ) {