From 0e7dfa1935e79c6dbf7a5da5abedd3543afb054e Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 14 Dec 2015 21:44:48 +0000 Subject: [PATCH] HHH-10371 - LocalDate value changes after fetching the row from the database --- .../type/descriptor/java/LocalDateJavaDescriptor.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hibernate-java8/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java b/hibernate-java8/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java index 08d0f2b379..d911e0fb04 100644 --- a/hibernate-java8/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java +++ b/hibernate-java8/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaDescriptor.java @@ -111,11 +111,15 @@ public class LocalDateJavaDescriptor extends AbstractTypeDescriptor { } if ( Date.class.isInstance( value ) ) { - final Date ts = (Date) value; - final Instant instant = Instant.ofEpochMilli( ts.getTime() ); - return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() ).toLocalDate(); + if ( java.sql.Date.class.isInstance( value ) ) { + return ((java.sql.Date) value).toLocalDate(); + } + else { + return Instant.ofEpochMilli( ((Date) value).getTime() ).atZone( ZoneId.systemDefault() ).toLocalDate(); + } } throw unknownWrap( value.getClass() ); } + }