Prevented possible NullPointerException's
[jpa-converters] / src / main / java / de / juplo / jpa / converters / LocalTimeConverter.java
1 package de.juplo.jpa.converters;
2
3 import java.sql.Time;
4 import java.time.LocalTime;
5 import javax.persistence.AttributeConverter;
6 import javax.persistence.Converter;
7
8
9 /**
10  * Converts a {@link LocalTime} to a {@link Time}.
11  * @author Kai Moritz
12  */
13 @Converter(autoApply = true)
14 public class LocalTimeConverter implements AttributeConverter<LocalTime, Time>
15 {
16   @Override
17   public Time convertToDatabaseColumn(LocalTime lt)
18   {
19     if (lt == null)
20       return null;
21     return Time.valueOf(lt);
22   }
23
24   @Override
25   public LocalTime convertToEntityAttribute(Time time)
26   {
27     if (time == null)
28       return null;
29     return time.toLocalTime();
30   }
31 }