未找到 hibernate JDBC 类型
hibernate对此oracle数据类型有任何映射吗:(10G) 带有时区的时间戳(6)
我得到: 没有 JDBC 类型的方言映射:-101
我的经理不想执行以下操作:registerHibernateType(-101, Hibernate.getText().getname())
他认为这太多了。:) 我还有什么选择?
Does hibernate have any mapping for this oracle data type:(10G)
TIMESTAMP(6) WITH TIME ZONE
I am getting:
No Dialect mapping for JDBC type: -101
My manager does not want to do the: registerHibernateType(-101, Hibernate.getText().getname())
He thinks it is too much.:)
What alternative can I have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您给自己提供的答案更像是一种解决方法,而不是正确的解决方案。为了寻求答案的访问者,我将提供我对此的看法:
1)数据库基于日期的字段应始终设置为 UTC,而不是特定的时区。使用时区信息进行日期计算是不必要的复杂性。请记住,世界上许多国家/地区的时区通常每年更改两次(“夏令时”)。为什么只有少数 RDMBS 支持这一点,也是 Hibernate 开发人员拒绝支持这种数据类型的原因。 Hibernate 的补丁非常简单(一行代码),但其含义却并非如此。
2)将“带有时区的时间戳”转换为字符串只会在以后引起问题。将其作为字符串检索后,您需要将其再次转换为日期/日历对象,这是不必要的开销。更不用说与此操作相关的风险。
3)如果您需要知道某个用户位于哪个时区,只需存储表示时区偏移量的字符串(例如“欧洲/布拉格”)。您可以在 Java 中使用它来构建带有日期/时间和时区的日历,因为它会为您处理 DST。
The answer you provide to yourself is more like a workaround than a proper solution. For the sake of the visitors looking for an answer, I'll provide my view on this:
1) Database date-based fields should be always set to UTC, never with a specific timezone. Date calculation with timezone information is an unneeded complexity. Remember that timezones usually changes twice a year for a lot of countries in the world ("daylight saving time"). There's a reason why only a few RDMBS' supports this, and there's a reason why Hibernate developers refuse to support this data-type. The patch for Hibernate is simple enough (one line of code), the implications aren't.
2) Converting your "timestamp with timezone" to a String will only cause problems later. Once you retrieve it as String, you'll need to convert it again to a Date/Calendar object, an unneeded overhead. Not to mention the risks associated with this operation.
3) If you need to know in which timezone is some user, just store the String representing the timezone offset (like "Europe/Prague"). You can use this in Java to build a Calendar with date/time and timezone, as it'll take care of DST for you.
现在,我通过以下方式解决了这个问题:
这确保了当查询返回时,该字段的数据类型为“String”
For now, I solved the problem by:
This ensures that when the query returns, the field has datatype 'String'