How to use the Java 8 LocalDateTime with JPA and Hibernate

For any Hibernate 5.x users, there is

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
    <version>5.0.0.Final</version>
</dependency>

You don’t need to do anything else. Just add the dependency, and the Java 8 time types should work like any other basic types, no annotations required.

private LocalDateTime invalidateTokenDate;

Note: this won’t save to timestamp type though. Testing with MySQL, it saves to datetime type.

Leave a Comment