他们婚姻幸福吗?
我正在使用最新版本的 hibernate (4) 和 joda-time hibernate support 的 1.3 版本,我也相信这是当前的最新版本。
使用注释时,一切似乎都正常(按预期创建日期列):
@Column
@Type(type="org.joda.time.contrib.hibernate.PersistentLocalDate")
private LocalDate myDate;
将这些版本一起使用是否有任何已知问题?
更新 事实证明,列已创建但无法填充任何数据:
处理程序处理失败;嵌套异常是 java.lang.AbstractMethodError: org.joda.time.contrib.hibernate.PersistentLocalDateTime.nullSafeSet
它们不兼容,我应该使用 usertype . 请参阅下面的答案。
最佳答案
明显缺乏文档,这意味着写下集成所需的步骤可能对我有所帮助。确保您的库是最新的。
你需要:[假设你已经有 hibernate4]
joda-time最新版本
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.0</version>
</dependency>
和用户类型库
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.0.0.CR1</version>
</dependency>
然后在实体类中使用以下内容(不必是 LocalDateTime,可以是任何可用的持久类):
import org.joda.time.LocalDateTime;
对于列定义:
@Column(name="updated", nullable = false)
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private LocalDateTime updated;
关于java - hibernate 4 和 joda-time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8974747/