Skip to content

JPA 2.1 attribute converters for JSR-310 temporal types (java.time.*)

License

Notifications You must be signed in to change notification settings

perceptron8/datetime-jpa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datetime-jpa Build Status Maven Central

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

Credits

Usage

<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;
    …
}

About

JPA 2.1 attribute converters for JSR-310 temporal types (java.time.*)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages