For type TIMESTAMP you can use this converter:
@Converter(autoApply = true) public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDateTime, Timestamp> { @Override public Timestamp convertToDatabaseColumn(LocalDateTime datetime) { return datetime == null ? null : Timestamp.valueOf(datetime); } @Override public LocalDateTime convertToEntityAttribute(Timestamp timestamp) { return timestamp == null ? null : timestamp.toLocalDateTime(); } }
For type DATE, you can use this converter:
@Converter(autoApply = true) public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> { @Override public Date convertToDatabaseColumn(LocalDate date) { return date == null ? null : Date.valueOf(date); } @Override public LocalDate convertToEntityAttribute(Date date) { return date == null ? null : date.toLocalDate(); } }
For type TIME you can use this converter:
@Converter(autoApply = true) public class LocalTimeAttributeConverter implements AttributeConverter<LocalTime, Time> { @Override public Time convertToDatabaseColumn(LocalTime time) { return time == null ? null : Time.valueOf(time); } @Override public LocalTime convertToEntityAttribute(Time time) { return time == null ? null : time.toLocalTime(); } }
Paco Oct 10 '17 at 16:59 on 2017-10-10 16:59
source share