Spring Boot: using Joda Time on JPA entity with Hibernate

Joda Time is the standard de facto for managing dates in Java applications. Using it on Spring is straightforward, simply add the right dependency to your project and you can use it. But some attention is needed if you want use them for dates fields in your JPA entity class and correctly map them as date types on your database.

In the following we show the code for using joda types in a JPA entity class, given Hibernate as JPA implementation.

The code works with Spring Boot 1.2.2 and Hibernate 4.5.


Add the following dependencies on your pom.xml file:



The first dependency provide the joda time library while the second one provides mappings for joda types to use in JPA entities.


Enable autoregistration of Jadira Usertypes in the application.properties file adding the following line:

spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true

Look here an example of an application.properties file using this configuration.

JPA entity’s fields

This is all you need for using Joda Time types with JPA and Hibernate!

Now you can add Joda types on your JPA entity:

// Will be mapped as DATETIME (on MySQL)
private DateTime createTime;

// Will be mapped as DATE (on MySQL), i.e. only date without timestamp
private LocalDate birthdayDate;

You can see here for an example entity using these types.

Spring controllers

In order to bind dates from Spring controllers add the jackson data bind library:



Now you can bind JSON to Java object containing Joda dates from your controller.

For example, having this entity class:

@Table(name = "users")
public class User {

  @GeneratedValue(strategy = GenerationType.AUTO)
  private long id;

  // For JSON binding use the format: "1970-01-01T00:00:00.000+0000"
  private DateTime createTime;

  // For JSON binding use the format: "1970-01-01" (yyyy-MM-dd)
  private LocalDate birthdayDate;

  // Getters and setters methods
  // ...

It can be used a controller method like this to receiving a User object as JSON:

    value = "/user",
    method = RequestMethod.POST,
    consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addUser(@RequestBody User user) {
  // Handle the User object here
  // ....

Sending a JSON like this:


will be created a User object binding its birthday date.

The @Type annotation

If you don’t want to enable the autoRegisterUserTypes configuration in the application.properties you can manually specify the Jadira type mapping to use (see here), using the @Type annotation:

// Will be mapped as DATETIME (on MySQL)
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime createTime;

// Will be mapped as DATE (on MySQL), i.e. only date without timestamp
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate birthdayDate;

Try it yourself

You can get the code used in this post from our github repository and try it by yourself:










  • Devarajan

    Does it work with Hibernate 5?

    • Hi Devarajan, I didn’t tried it on Hibernate 5 yet.. If you make a try let me know if it works. Thanks.

      • Ash

        I had dependency issues with the version you used when using with Hibernate 5, My spring beans wouldnt init correctly, which were previously working before adding that dependancy.

        I ended up using


        This got it working for me


Category BootstrapCategory CoffeescriptCategory DrupalCategory GravCategory HTMLCategory JavascriptCategory JoomlaCategory jQueryCategory LaravelCategory MagentoCategory PHPCategory SharePointCategory SpringCategory ThymeleafCategory WordPressCategory Workflow


Developed and designed by Netgloo
© 2019 Netgloo