JPA 2.1¹ attribute converters for JSR-310 temporal types (java.time.*).
Following conversions are supported:
Java SE 8 | ANSI SQL |
---|---|
DayOfWeek | INTEGER |
LocalDate¹ | DATE |
LocalDateTime¹ | TIMESTAMP |
LocalTime¹ | TIME |
Month | INTEGER |
MonthDay | DATE, LONG² |
Year | DATE², INTEGER |
YearMonth | DATE, LONG² |
¹ - supported natively as of JPA 2.2
² - use @Convert
to choose this one
<dependency>
<groupId>com.github.perceptron8</groupId>
<artifactId>datetime-jpa</artifactId>
<version>0.1.0</version>
</dependency>
<persistence-unit>
…
<class>com.github.perceptron8.datetime.jpa.LocalTimeToTimeConverter</class>
<class>com.github.perceptron8.datetime.jpa.LocalDateToDateConverter</class>
<class>com.github.perceptron8.datetime.jpa.LocalDateTimeToTimestampConverter</class>
…
<class>com.github.perceptron8.datetime.jpa.DayOfWeekToIntegerConverter</class>
<class>com.github.perceptron8.datetime.jpa.MonthToIntegerConverter</class>
<class>com.github.perceptron8.datetime.jpa.YearToDateConverter</class>
<class>com.github.perceptron8.datetime.jpa.YearToIntegerConverter</class>
…
<class>com.github.perceptron8.datetime.jpa.MonthDayToDateConverter</class>
<class>com.github.perceptron8.datetime.jpa.MonthDayToLongConverter</class>
<class>com.github.perceptron8.datetime.jpa.YearMonthToDateConverter</class>
<class>com.github.perceptron8.datetime.jpa.YearMonthToLongConverter</class>
…
</persistence-unit>
@Entity
public class SampleEntity {
…
private LocalDate localDate;
private LocalTime localTime;
private LocalDateTime localDateTime;
…
private DayOfWeek dayOfWeek;
private Month month;
private Year year;
…
private MonthDay monthDay;
private YearMonth yearMonth;
…
}