1 package de.juplo.jpa.converters;
3 import java.time.ZonedDateTime;
4 import java.util.GregorianCalendar;
5 import javax.persistence.AttributeConverter;
6 import javax.persistence.Converter;
10 * Converts a {@link ZonedDateTime} to a {@link GregorianCalendar}, as suggested
11 * in the official Java 8 Time tutorial.
13 * The {@link GregorianCalendar} 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 ZonedDateTimeConverter implements AttributeConverter<ZonedDateTime, GregorianCalendar>
23 public GregorianCalendar convertToDatabaseColumn(ZonedDateTime zdt)
25 return GregorianCalendar.from(zdt);
29 public ZonedDateTime convertToEntityAttribute(GregorianCalendar calendar)
31 return calendar.toZonedDateTime();