休眠 4 和 joda 时间 [英] hibernate 4 and joda-time

查看:24
本文介绍了休眠 4 和 joda 时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们的婚姻幸福吗?

我正在使用最新版本的 hibernate (4) 和 1.3 版 joda-time hibernate 支持,我也相信这是当前的最新版本.

I am using the latest version of hibernate (4) and version 1.3 of joda-time hibernate support, which I also believe to be the current latest release.

使用注释时,一切似乎都正常(按预期创建日期列):

Everything seems to be working OK (date columns created as expected) when using annotations :

@Column
@Type(type="org.joda.time.contrib.hibernate.PersistentLocalDate")
private LocalDate myDate; 

他们一起使用这些版本是否有任何已知问题?

Are their any known problems with using these versions together ?

更新事实证明列已创建但无法填充任何数据:

Update Well turns out the columns get created but unable to populate with any data :

处理程序处理失败;嵌套异常是 java.lang.AbstractMethodError: org.joda.time.contrib.hibernate.PersistentLocalDateTime.nullSafeSet

它们不兼容,我应该使用 usertype.请参阅下面的答案.

They are incompatible, and I should be using usertype. See answer below.

推荐答案

明显缺乏文档,这意味着写下集成所需的步骤可能对我有所帮助.确保您的库是最新的.

A distinct paucity of documentation, means it might be helpful for me to write down the steps required for integration. Make sure your libraries are up to date.

你需要:[假设你已经有 hibernate4]

You'll need : [assuming you already have hibernate4]

最新版本的 joda-time

Latest version of 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,可以是任何可用的持久化类):

Then use the following in entity classes (doesn't have to be LocalDateTime, could be any of the persisted classes available) :

import org.joda.time.LocalDateTime;

和列定义:

@Column(name="updated", nullable = false)
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private LocalDateTime updated;

这篇关于休眠 4 和 joda 时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆