-
-
Save rponte/a9bbc9b3850432836874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fx.time; | |
| import java.sql.Date; | |
| import java.time.LocalDate; | |
| import javax.persistence.AttributeConverter; | |
| import javax.persistence.Converter; | |
| @Converter(autoApply = true) | |
| public class PersistentLocalDate implements AttributeConverter<LocalDate, Date> { | |
| @Override | |
| public Date convertToDatabaseColumn(LocalDate value) { | |
| return value == null ? null : Date.valueOf(value); | |
| } | |
| @Override | |
| public LocalDate convertToEntityAttribute(Date value) { | |
| return value == null ? null : value.toLocalDate(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fx.time; | |
| import java.sql.Timestamp; | |
| import java.time.LocalDateTime; | |
| import javax.persistence.AttributeConverter; | |
| import javax.persistence.Converter; | |
| @Converter(autoApply = true) | |
| public class PersistentLocalDateTime implements AttributeConverter<LocalDateTime, Timestamp> { | |
| @Override | |
| public java.sql.Timestamp convertToDatabaseColumn(LocalDateTime value) { | |
| return value == null ? null : Timestamp.valueOf(value); | |
| } | |
| @Override | |
| public LocalDateTime convertToEntityAttribute(Timestamp value) { | |
| return value == null ? null : value.toLocalDateTime(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fx.time; | |
| import java.sql.Date; | |
| import java.time.YearMonth; | |
| import javax.persistence.AttributeConverter; | |
| import javax.persistence.Converter; | |
| @Converter(autoApply = true) | |
| public class PersistentYearMonth implements AttributeConverter<YearMonth, Date> { | |
| @Override | |
| public Date convertToDatabaseColumn(YearMonth value) { | |
| return value == null ? null : Date.valueOf(value.atDay(1)); | |
| } | |
| @Override | |
| public YearMonth convertToEntityAttribute(Date value) { | |
| return value == null ? null : YearMonth.from(value.toLocalDate()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment