Sleep Migration 5 of 3

I am moving on to Hibernate 5.0.3.Final from 3. In 3.x, I use joda time to store LocalDateTime in Oracle. Now I see that sleep mode 5 does not support iodine-time. Please let me know which one would be the best alternative?

Here is a sample code.

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; 
+5
source share
1 answer

I switched from Hibernate from 4 to 5, so it may be convenient for you that I did, removed all the Joda time dependencies, and replaced the classes with a new Java Date Api like this.

From Joda's time

 @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime") private LocalDateTime startDate; @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") private DateTime creationDate; 

K 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 any

  <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 on how to convert Joda Time Type to Java Date Time http://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html

+3
source

Source: https://habr.com/ru/post/1236035/


All Articles