【问题标题】:How to use jodaTime with hibernate如何在休眠中使用 jodaTime
【发布时间】:2015-11-07 06:48:07
【问题描述】:

我想在休眠中使用 JodaTime LocalDate。我是这样写的:

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DATE_DEBUT", nullable = false)
@Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDate")
private LocalDate dateDebut;

但它没有用。我收到此错误:

Caused by: Exception [EclipseLink-7165] (Eclipse Persistence Services -   2.5.2.v20140319-9ad6abd):   org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class org.joda.time.LocalDate] for the attribute [dateDebut] on the entity class [class ch.test.application.beans.mandat.Mandat] is not a valid type for a temporal mapping. The attribute must be defined as java.util.Date or java.util.Calendar.

你知道为什么吗?

谢谢

【问题讨论】:

  • 您使用的是什么版本的 Hibernate 和 JodaTime?向我们展示 Maven POM 的相关部分。
  • 您意识到您根本没有使用 Hibernate,而是使用 EclipseLink? EclipseLink 不会打扰 Hibernate 类型和注释。

标签: java hibernate jpa jodatime


【解决方案1】:

您可以使用Jadira

你所要做的就是将它添加为依赖项,然后像这样添加 anotae:

@Column
  @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
  private DateTime endTime;

欲了解更多信息,请查看他们的website

还有另一个库将 Joda Time 与 Joda 自己的 Hibernate 集成在一起。这是link。但就我个人而言,我无法让它为我工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 2010-12-17
    • 2019-02-23
    • 2011-02-09
    • 2023-03-17
    • 1970-01-01
    • 2016-05-17
    相关资源
    最近更新 更多