From 1c32d9ec8c9dd7b65bcfdd89d2b75d16609e299c Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 21 Dec 2015 23:45:48 +0100 Subject: [PATCH] Implemented a Year-to-Integer converter --- .../juplo/jpa/converters/YearConverter.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/de/juplo/jpa/converters/YearConverter.java diff --git a/src/main/java/de/juplo/jpa/converters/YearConverter.java b/src/main/java/de/juplo/jpa/converters/YearConverter.java new file mode 100644 index 0000000..59875a6 --- /dev/null +++ b/src/main/java/de/juplo/jpa/converters/YearConverter.java @@ -0,0 +1,26 @@ +package de.juplo.jpa.converters; + +import java.time.Year; +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + + +/** + * Converts a {@link Year} into its {@link Integer} representation. + * @author Kai Moritz + */ +@Converter(autoApply = true) +public class YearConverter implements AttributeConverter +{ + @Override + public Integer convertToDatabaseColumn(Year year) + { + return year.getValue(); + } + + @Override + public Year convertToEntityAttribute(Integer integer) + { + return Year.of(integer); + } +} -- 2.20.1