The Sad State of JSR-310 Support in JPA 2.2

Offically JPA 2.2 supports JSR-310 / Java Date Time API datatypes. In order to evaluate the implementations I created a GitHub repostory.

Before looking at the results it has to be noted that proper JSR-310 support in JDBC applications (and therefore JPA applications as well) can only be achieved with either JDBC 4.2 support and .getObject(int|String, Class) or vendor extensions. Proper JSR-310 can not be achieved by relying on the java.sql types in JDBC. The original JPA_SPEC-63 expanded on this, unfortunately it seems as if this has not made it into the final specification and this is what causes most of the issues.

I have only looked at EclipseLink 2.7.1 and Hibernate 5.3.0.CR1, the only JPA 2.2 implementations I know of.

Hiberante suffers from several issues by design. Hibernate chose not to directly use the java.time data types but instead convert through java.sql types. This means that:

  • LocalDateTime can not handle values that fall into a DST transation in the current JVM time zone
  • LocalTime is truncated from nanoseconds to milliseconds or even seconds
  • OffsetDateTime is always converted to the JVM time zone

The Hiberante team has been made aware of these issues but believes the current approach is the right one.

EclipseLink suffers from a variety of issues:

  • LocalDateTime can not handle values that fall into a DST transition in the current JVM time zone
  • LocalTime is truncated from nanoseconds to milliseconds or even seconds on HSQLDB
  • OffsetDateTime seems to suffer different issues based on the database:
    • on H2 the conversion between org.h2.api.TimestampWithTimeZone and OffsetDateTime throws an exception
    • on SQL Server the conversion between microsoft.sql.DateTimeOffset and OffsetDateTime throws an exception
    • on HSQLDB the time zone offset seems to be converted to the one from the JVM

Unfortunatley it seems as if JSR-310 in JPA 2.2 is not yet ready for prime time and projects like threeten-jpa are still needed. If you plan to use JSR-310 with JPA make sure you have a rigorous test suite in place in order to make sure your entire stack is ready. For inspiration have a look at the tests in state-of-jpa-310.

For a list of reported issue see bug 533912 and HHH-11835.