在数据库中存储 joda-time 日期时间
我的应用程序已经使用 Joda-time 进行日期操作,并计划在不久的将来升级到 jsr 310。
现在我需要使用 jpa 2 和 hibernate 在数据库中存储非常准确的时间戳,但 java.util.Date 不存储毫秒值。
我找到了 UserType 并像这样配置了我的entitybean
@Column( name = "TRANSACTION_TIME" )
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime transactionTime;
,但它仍然不存储毫秒。
我传入了这个2010-11-02 12:02:54.945
,但是当我检索它时,它是2010-11-02 12:02:54.000
。
我还需要做什么才能存储毫秒以及可能的时区?
更新 我刚刚检查过,毫秒实际上已到达数据库,但 Hibernate 并未将其包含在返回的结果中。相同的格式化程序打印了两个结果,因此不可能是格式化问题
My application already uses Joda-time for date manipulation with plans to upgrade to jsr 310 in the near future.
Now I need to store VERY accurate timestamp in the database using jpa 2 and hibernate, but java.util.Date
is not storing the millisecond value.
I found UserType and configured my entitybean like this
@Column( name = "TRANSACTION_TIME" )
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime transactionTime;
but it still doesn't store the milliseconds.
I passed in this 2010-11-02 12:02:54.945
but when I retrieved it, it was 2010-11-02 12:02:54.000
.
What else do I have to do to get the milliseconds stored and possibly the time zone?
UPDATE
I have just checked and the milliseconds actually make it to the database but Hibernate does not include it in the returned results. The same formatter printed the two results so it can't be formatting problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能不完全是您想要的,但您可以将时间存储为数字(=自纪元以来的毫秒数)而不是日期时间字段。
This might not be exactly what you want, but you could store the time as a number (=miliseconds since epoch) instead of a datetime field.
Oracle DATE 数据类型不存储小数秒。您需要使用 TIMESTAMP 或前面建议的数字列。请参阅:http://knol.google.com/k/oracle -日期和时间数据类型
Oracle DATE datatype does not store fractional seconds. You need to use TIMESTAMP or a numeric column as previously suggested. See: http://knol.google.com/k/oracle-date-and-time-data-types