1 package de.juplo.jpa.converters;
3 import java.time.Duration;
4 import java.time.temporal.ChronoUnit;
5 import java.time.temporal.TemporalAmount;
6 import javax.persistence.AttributeConverter;
7 import javax.persistence.Converter;
11 * Converts a {@link TemporalAmount} into a {@link Long} representing seconds.
15 public class TemporalAmountToSecondsConverter implements AttributeConverter<TemporalAmount, Long>
18 public Long convertToDatabaseColumn(TemporalAmount amount)
20 return amount.get(ChronoUnit.SECONDS);
24 public TemporalAmount convertToEntityAttribute(Long seconds)
26 return Duration.ofSeconds(seconds);