--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing days.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToDaysConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.DAYS);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long days)
+ {
+ return Duration.ofDays(days);
+ }
+}
--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing hours.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToHoursConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.HOURS);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long hours)
+ {
+ return Duration.ofHours(hours);
+ }
+}
--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing
+ * microseconds.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToMicrosConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.MICROS);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long micros)
+ {
+ return Duration.of(micros, ChronoUnit.MICROS);
+ }
+}
--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing
+ * milliseconds.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToMillisConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.MILLIS);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long millis)
+ {
+ return Duration.ofMillis(millis);
+ }
+}
--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing minutes.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToMinutesConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.MINUTES);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long minutes)
+ {
+ return Duration.ofMinutes(minutes);
+ }
+}
--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing
+ * nanoseconds.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToNanosConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.NANOS);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long nanos)
+ {
+ return Duration.ofNanos(nanos);
+ }
+}
--- /dev/null
+package de.juplo.jpa.converters;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAmount;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link TemporalAmount} into a {@link Long} representing seconds.
+ * @author Kai Moritz
+ */
+@Converter
+public class TemporalAmountToSecondsConverter implements AttributeConverter<TemporalAmount, Long>
+{
+ @Override
+ public Long convertToDatabaseColumn(TemporalAmount amount)
+ {
+ return amount.get(ChronoUnit.SECONDS);
+ }
+
+ @Override
+ public TemporalAmount convertToEntityAttribute(Long seconds)
+ {
+ return Duration.ofSeconds(seconds);
+ }
+}