javahibernatejodatimehibernate-6.x

Is Joda DateTime supported by Hibernate 6?


I am trying to upgrade my spring boot from 2.7.X to 3.2.X. But the following code is not compiling.

@jakarta.persistence.Entity
public class Order {
... 
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")//can't resolve method type
private DateTime createdOn;

}

Is Joda DateTime supported by Hibernate 6.4.X? If yes, how to migrate the above code?


Solution

  • java.time

    Given below is a notice on the home page of Joda-Time:

    Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310) - a core part of the JDK which replaces this project.

    The modern date/time API, java.time was released as part of Java 8 in March 2024 (ten years ago). Since then, it is highly recommended to switch to the java.time API from both, the legacy java.util API as well as the Joda-Time API.

    I recommend you change your code to java.time API as follow:

    @Type(type="org.hibernate.type.ZonedDateTimeType")
    private java.time.ZonedDateTime createdOn;
    

    Given below is the Maven dependency for it:

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

    Remove all Maven dependencies of Joda-Time and Jadira.

    Here is an article written by the creator of Joda-Time and architect of java.time API.

    Learn about the modern date-time API from Trail: Date Time