问题描述
我在Play应用中使用Jodatime,但目前必须做一堆来回/转换为 java.util.Date
和<$ c
由于jodatime包含在Play发行版中,我认为可能有更好的方法做这个。有什么办法可以让我的模型字段 DateTime
s而不是 java.util.Date
和 java.sql.Time
所以转换是自动完成的?是否有另一种简化这种方法?
对于Hibernate 3,将以下注释添加到日期字段中:
@Type(type =org.joda.time.contrib.hibernate.PersistentDateTime)
Hibernate现在会为你做一些肮脏的工作。
(确保你有在你的classpath中)
更新:
对于Hibernate 4和5,添加以下注释:
@Type(type =org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime)
(确保你有 classpath中的jadira-usertype-core.jar)
I'm using Jodatime in my Play app, but currently having to do a bunch of converting back and forth from/to java.util.Date
and java.sql.Time
.
Since jodatime is included in the Play distribution, I'm thinking there's probably a better way to do this. Is there any way I can make my Model fields DateTime
s instead of java.util.Date
and java.sql.Time
so the conversion is done automatically? Is there another way of streamlining this?
For Hibernate 3 add the following annotation to your date field:
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
Hibernate will now do the dirty work for you.
(Make sure you have joda-time-hibernate.jar in your classpath)
UPDATE:
For Hibernate 4 and 5 add the following annotation:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
(Make sure you have jadira-usertype-core.jar in your classpath)
这篇关于通过Hibernate保持Joda时间的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!