Converters must convert to a data-type, know by the database
[jpa-converters] / src / main / java / de / juplo / jpa / converters / InstantConverter.java
index fe6bbd6..28cf149 100644 (file)
@@ -1,33 +1,27 @@
 package de.juplo.jpa.converters;
 
+import java.sql.Timestamp;
 import java.time.Instant;
-import java.util.Date;
 import javax.persistence.AttributeConverter;
 import javax.persistence.Converter;
 
 
 /**
- * Converts an {@link Instant} to 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.TIMESTAMP} with the help of the
- * {@link java.persist.Tmporal}-annotation.
- * @see https://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html
+ * Converts an {@link Instant} to a {@link Timestamp}.
  * @author Kai Moritz
  */
 @Converter(autoApply = true)
-public class InstantConverter implements AttributeConverter<Instant, Date>
+public class InstantConverter implements AttributeConverter<Instant, Timestamp>
 {
   @Override
-  public Date convertToDatabaseColumn(Instant instant)
+  public Timestamp convertToDatabaseColumn(Instant instant)
   {
-    return Date.from(instant);
+    return Timestamp.from(instant);
   }
 
   @Override
-  public Instant convertToEntityAttribute(Date date)
+  public Instant convertToEntityAttribute(Timestamp ts)
   {
-    return date.toInstant();
+    return ts.toInstant();
   }
 }