1 package de.juplo.jpa.converters;
3 import java.time.Instant;
5 import javax.persistence.AttributeConverter;
6 import javax.persistence.Converter;
10 * Converts an {@link Instant} to a {@link Date}, as suggested in
11 * the official Java 8 Time tutorial.
13 * The {@link Date} can then be persisted as
14 * {@link java.persistene.TemporalType.TIMESTAMP} with the help of the
15 * {@link java.persist.Tmporal}-annotation.
16 * @see https://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html
19 @Converter(autoApply = true)
20 public class InstantConverter implements AttributeConverter<Instant, Date>
23 public Date convertToDatabaseColumn(Instant instant)
25 return Date.from(instant);
29 public Instant convertToEntityAttribute(Date date)
31 return date.toInstant();