冬眠4和乔达时间 [英] hibernate 4 and joda-time

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

问题描述



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



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

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

他们在使用这些版本时遇到的任何已知问题?

更新
结果列创建完成,但无法填充任何数据:

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

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

解决方案

明显缺乏文档,意味着我可能会写下集成所需的步骤。确保你的库是最新的。



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



最新版本的乔达时间

 <依赖关系> 
< groupId> joda-time< / groupId>
< artifactId> joda-time< / artifactId>
< version> 2.0< / version>
< /依赖关系>

和usertype lib

 <依赖性> 
< groupId> org.jadira.usertype< / groupId>
< artifactId> usertype.core< / artifactId>
< version> 3.0.0.CR1< / version>
< /依赖关系>

然后在实体类中使用以下内容(不一定是LocalDateTime,可以是任何持久化类可用):

  import org.joda.time.LocalDateTime; 

以及列定义:

<$ p $
@Type(type =org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime)
private LocalDateTime更新;


are they happily married ?

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 :

Handler processing failed; nested exception is java.lang.AbstractMethodError: org.joda.time.contrib.hibernate.PersistentLocalDateTime.nullSafeSet

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.

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

Latest version of joda-time

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.0</version>
</dependency>

and usertype lib

<dependency>
    <groupId>org.jadira.usertype</groupId>
    <artifactId>usertype.core</artifactId>
    <version>3.0.0.CR1</version>
</dependency>

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;

and for column definition:

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

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

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