Converters must convert to a data-type, know by the database
[jpa-converters] / src / main / java / de / juplo / jpa / converters / LocalDateConverter.java
index d6a5c51..2606602 100644 (file)
@@ -1,25 +1,13 @@
 package de.juplo.jpa.converters;
 
-import java.time.Instant;
+import java.sql.Date;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneOffset;
-import java.util.Date;
 import javax.persistence.AttributeConverter;
 import javax.persistence.Converter;
 
 
 /**
- * Converts a {@link LocalDate} to a {@link Date}, by converting it into
- * an {@Instant} for the GMT-timezone at {@link LocalTime.MIDNIGHT} and then
- * convering that {@link Instant} into a {@link Date} as suggested in the
- * official Java 8 Time tutorial.
- * <p>
- * The {@link Date} can then be persisted as
- * {@link java.persistene.TemporalType.DATE} with the help of the
- * {@link java.persist.Tmporal}-annotation.
- * @see https://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html
+ * Converts a {@link LocalDate} to a {@link Date}.
  * @author Kai Moritz
  */
 @Converter(autoApply = true)
@@ -28,12 +16,12 @@ public class LocalDateConverter implements AttributeConverter<LocalDate, Date>
   @Override
   public Date convertToDatabaseColumn(LocalDate ld)
   {
-    return Date.from(LocalDateTime.of(ld, LocalTime.MIDNIGHT).toInstant(ZoneOffset.UTC));
+    return Date.valueOf(ld);
   }
 
   @Override
   public LocalDate convertToEntityAttribute(Date date)
   {
-    return LocalDate.from(date.toInstant());
+    return date.toLocalDate();
   }
 }