在Hibernate中持久化Joda DateTime而不是Java Date [英] Persisting Joda DateTime instead of Java Date in Hibernate

查看:166
本文介绍了在Hibernate中持久化Joda DateTime而不是Java Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的实体当前包含java Date属性。我开始使用Joda Time来进行日期操作和计算。这意味着我不得不将我的日期转换为Joda DateTime对象,然后再次。

My entities currently contain java Date properties. I'm starting to use Joda Time for date manipulation and calculations quite frequently. This means that I'm constantly having to convert my Dates into Joda DateTime objects and back again.

所以我想知道,有什么理由我不应该只是改变我的实体存储Joda DateTime对象而不是Java Date对象?

So I was wondering, is there any reason I shouldn't just change my entities to store Joda DateTime objects instead of Java Date objects?

请注意,这些实体通过Hibernate持久化。我发现 jodatime-hibernate 项目,但我也在阅读Joda邮件列出它与新版本的hibernate不兼容。而且看起来好像维护不好。

Please note that these entities are persisted via Hibernate. I found the jodatime-hibernate project, but I also was reading on the Joda mailing list that it wasn't compatible with newer versions of hibernate. And it seems like it isn't very well maintained.

所以我想知道最好是继续在Date和DateTime之间转换,明智地开始持久化DateTime对象。我的关注是依赖于维护不良图书馆。

So I'm wondering if it would be best to just continue converting between Date and DateTime, or if it would be wise to start persisting DateTime objects. My concern is being reliant on a poorly maintained library.

编辑:请注意,我的目标之一是更好地存储时区信息。仅存储日期显示将日期保存在本地时区。由于我的应用程序可以在全球范围内使用,我也需要知道时区。 Joda Time Hibernate似乎也在用户指南中解决此问题。

Note that one of my objectives is to be better able to store timezone information. Storing just a Date appears to save the date in the local timezone. As my application can be used globally, I need to know the timezone as well. Joda Time Hibernate seems to address this as well in the user guide.

推荐答案

我认为使用Joda DateTime作为您的bean属性类型可能是一个好主意。然后,您可以让Hibernate进行转换并将属性另存为本地数据库日期格式。

I think using the Joda DateTime as your bean property type is probably a good idea. You can then have Hibernate do the conversion and save the property as the native database date format.

我已经亲自使用jodatime-hibernate,并没有遇到问题我们使用Hibernate 3.2.5GA)。

I have personally used jodatime-hibernate and have not had a problem with it (we're using Hibernate 3.2.5GA).

如果您对jodatime-hibernate有任何疑问,可以随时使用(我确定是所有的jodatime都是这样的) -hibernate)。

If you have concerns about jodatime-hibernate, you can always use Hibernate's custom type mapping mechanism (which I'm sure is all jodatime-hibernate does).

这篇关于在Hibernate中持久化Joda DateTime而不是Java Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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