Class ZonedDateTimeConverter

  • All Implemented Interfaces:
    javax.persistence.AttributeConverter<java.time.ZonedDateTime,​java.sql.Timestamp>

    public class ZonedDateTimeConverter
    extends java.lang.Object
    implements javax.persistence.AttributeConverter<java.time.ZonedDateTime,​java.sql.Timestamp>
    JPA converter to for storing/retrieving ZonedDateTime objects.

    Hibernate provides a default converter for ZonedDateTime, but it converts timestamp to a non-normalized format, e.g., 2019-09-01T01:01:01Z will be converted to 2019-09-01T01:01:01Z[UTC]. This converter solves that problem by explicitly calling ZoneId.normalized() to normalize the zone id.

    • Constructor Detail

      • ZonedDateTimeConverter

        public ZonedDateTimeConverter()
    • Method Detail

      • convertToDatabaseColumn

        @Nullable
        public java.sql.Timestamp convertToDatabaseColumn​(@Nullable
                                                          java.time.ZonedDateTime attribute)
        Specified by:
        convertToDatabaseColumn in interface javax.persistence.AttributeConverter<java.time.ZonedDateTime,​java.sql.Timestamp>
      • convertToEntityAttribute

        @Nullable
        public java.time.ZonedDateTime convertToEntityAttribute​(@Nullable
                                                                java.sql.Timestamp dbData)
        Specified by:
        convertToEntityAttribute in interface javax.persistence.AttributeConverter<java.time.ZonedDateTime,​java.sql.Timestamp>