Hibernate只要坚持日期 [英] Hibernate to persist Dates as long
本文介绍了Hibernate只要坚持日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法告诉Hibernate java.util.Date应该持久化?我需要这个来解决MySQL中缺少的毫秒分辨率问题。
你能想到这种方法的缺点吗?
解决方案
您可以使用虚拟属性来完成此功能。
并为Date对象添加一个get / set。 setter设置了long值,getter创建了一个新的Date。我看不到任何缺点,只是可能想要使用Date在你的应用程序中(这就是为什么我认为虚拟属性解决方案很好)
Is there a way to tell Hibernate that java.util.Date should be persisted as long? I need this to get around the missing millisecond resolution in MySQL.
Could you think of any drawbacks of this approach?
解决方案
you can do it with a virtual attribute.
So you map a long, and add a get/set for a Date object. The setter sets the long value and the getter creates a new Date with the long.
And I can't see any drawbacks, only that probably you want to use a Date in your app (that's why I think the virtual attribute solution is goodish)
这篇关于Hibernate只要坚持日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文