简体   繁体   English

从3迁移到Hibernate 5

[英]Migrating To Hibernate 5 from 3

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. 我正在从3.迁移到Hibernate 5.0.3.Final 3.在3.x我使用joda-time在oracle DB中持久化LocalDateTime。 Now I am seeing that hibernate 5 doesn't have a support to joda-time. 现在我看到hibernate 5对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. 我从Hibernate 4迁移到5,所以可能适合你,我做的是删除所有Joda Time依赖项并将类替换为新的Java Date Api,就像这样。

From Joda Time 来自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 到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 如果你有它,删除maven依赖项

    <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 并添加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 您可以看到有关如何将Joda时间类型转换为Java日期时间的更多详细信息http://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM