开发者

How can I instruct Hibernate to map a Java date to an Oracle DATE column using a time zone other than the local time zone?

How can I instruct Hibernate to map 开发者_如何学Ca Java date to and from an Oracle DATE column using a time zone other than the local time zone?


I'm not sure but I think that you'll have to use the OracleConnection.setSessionTimeZone(String regionName) method to set the session time zone.

To do that on the OracleConnection before having Hibernate dealing with it, the cleanest way would be to provide and use a custom implementation of o.h.c.ConnectionProvider.

See this related question.


Hibernate does not allow for specifying time zones by annotation or any other means. If you use Calendar instead of date, you can implement a workaround using HIbernate property AccessType and implementing the mapping yourself. The more advanced solution is to implement a custom UserType to map your Date or Calendar. Both solutions are explained in this blog post: http://dev-metal.blogspot.com/2010/11/mapping-dates-and-time-zones-with.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜