I am migrating to Hibernate 5.0.3.Final from 3. In 3.x I am using joda-time to persist LocalDateTime in oracle DB. Now I am seeing that hibernate 5 doesn't have a support to joda-time. Please let me know what would be the best alternative for it?
Here is code sample.
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;
public class ComponentHistory {
@Column(name = EntityConstants.CREATED_BY_COLUMN_NAME)
private String createdBy;
@Column(name = EntityConstants.CREATED_DATE_COLUMN_NAME)
@Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDateTime")
private LocalDateTime createdDate;
@Column(name = EntityConstants.UPDATED_BY_COLUMN_NAME)
private String updatedBy;
@Column(name = EntityConstants.UPDATED_DATE_COLUMN_NAME)
@Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDateTime")
private LocalDateTime updatedDate;
I migrated from Hibernate 4 to 5 so maybe can be suitable for you, what I did was remove all Joda Time dependencies and replace the classes to new Java Date Api, like this.
From Joda Time
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private LocalDateTime startDate;
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime creationDate;
To Java 8 Date
@Type(type="org.hibernate.type.LocalDateTimeType")
private java.time.LocalDateTime startDate;
@Type(type="org.hibernate.type.ZonedDateTimeType")
private java.time.ZonedDateTime creationDate;
Remove maven dependencies if you have it
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-hibernate</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.1.0.CR8</version>
</dependency>
And add hibernate-java8
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.0.4.Final</version>
</dependency>
You can see more details about how to convert Joda Time Type to Java Date Time http://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With