从3迁移到Hibernate 5 [英] Migrating To Hibernate 5 from 3
问题描述
我正在从3迁移到Hibernate 5.0.3.Final.在3.x中,我正在使用joda-time将LocalDateTime保留在oracle DB中.现在,我看到休眠5不支持joda-time.请让我知道什么是最好的选择?
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?
这是代码示例.
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;
推荐答案
我从Hibernate 4迁移到了5,所以也许适合您,我所做的是删除了所有Joda Time依赖项并将类替换为新的Java Date Api ,就像这样.
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.
从乔达时间开始
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private LocalDateTime startDate;
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime creationDate;
到Java 8日期
@Type(type="org.hibernate.type.LocalDateTimeType")
private java.time.LocalDateTime startDate;
@Type(type="org.hibernate.type.ZonedDateTimeType")
private java.time.ZonedDateTime creationDate;
如果有,请删除maven依赖项
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>
并添加hibernate-java8
And add hibernate-java8
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.0.4.Final</version>
</dependency>
您可以查看有关如何将Joda时间类型转换为Java日期时间的更多详细信息
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
这篇关于从3迁移到Hibernate 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!